Skip to content

Commit

Permalink
Minor Updates and added new files to gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
DawoodOballi committed Dec 6, 2020
1 parent f08837e commit 9342106
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 80 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,10 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb

# SQL
*.sql

# DOCUMENTS
*.docx
58 changes: 58 additions & 0 deletions BusinessLayerTesting/MockTests/OvertimeManagerShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//using IP_Booking_Overtime;
//using NUnit.Framework;
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Microsoft.EntityFrameworkCore;
//using IP_BusinessLayer;

//namespace BusinessLayerTesting.MockTests
//{

// [TestFixture]
// public class OvertimeManagerShould
// {
// OvertimeManager overtimeManager;

// [OneTimeSetUp]
// public void OneTimeSetUp()
// {
// var options = new DbContextOptionsBuilder<IndividualProject_DatabaseContext>()
// .UseInMemoryDatabase(databaseName: "IP_DB")
// .Options;
// var context = new IndividualProject_DatabaseContext(options);
// overtimeManager = new OvertimeManager(context);
// overtimeManager.CreateOvertimeList(new List<Overtime>
// {
// new Overtime() {Day = "Monday", StartTime = new TimeSpan(3, 0, 0), NumberOfHours = 3},
// new Overtime() {Day = "Tuesday", StartTime = new TimeSpan(16, 0, 0), NumberOfHours = 10},
// new Overtime() { Day = "Tuesday", StartTime = new TimeSpan(13, 0, 0), NumberOfHours = 4},
// new Overtime() {Day = "Wednesday", StartTime = new TimeSpan(2, 0, 0), NumberOfHours = 6},
// new Overtime() {Day = "Thursday", StartTime = new TimeSpan(11, 0, 0), NumberOfHours = 8},
// new Overtime() {Day = "Thursday", StartTime = new TimeSpan(0, 0, 0), NumberOfHours = 7},
// new Overtime() {Day = "Friday", StartTime = new TimeSpan(23, 0, 0), NumberOfHours = 5},
// new Overtime() {Day = "Friday", StartTime = new TimeSpan(14, 0, 0), NumberOfHours = 4},
// new Overtime() {Day = "Friday", StartTime = new TimeSpan(17, 0, 0), NumberOfHours = 6},
// });
// }

// [Test]
// public void GivenAValidOvertime_Returns_AOvertimeObject()
// {
// Assert.That(overtimeManager.GetOvertime(2), Is.InstanceOf<Overtime>());
// }

// [Test]
// public void GivenANewOvertime_ItGetsAddedToTheDatabase()
// {
// object item = new Overtime() { Day = "Monday", StartTime = TimeSpan.Parse("18:00"), NumberOfHours = 5 };
// overtimeManager.GetSelectedOvertime(item);
// Overtime newItem = (Overtime)item;
// overtimeManager.CreateOvertime(newItem.Day, newItem.StartTime.Value, newItem.NumberOfHours.ToString());
// overtimeManager.GetSelectedOvertime(newItem);
// Assert.That(newItem.StartTime, Is.EqualTo(new TimeSpan(18, 0, 0)));
// Assert.That(newItem.Day, Is.EqualTo("Monday"));
// overtimeManager.RemoveOvertime(newItem);
// }
// }
//}
13 changes: 0 additions & 13 deletions BusinessLayerTesting/MockTests/OvertimeSetterTests.cs

This file was deleted.

34 changes: 34 additions & 0 deletions BusinessLayerTesting/MockTests/Overtime_UserCreatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using Moq;
using IP_BusinessLayer;
using IP_Booking_Overtime;

namespace BusinessLayerTesting.MockTests
{
[TestFixture]
public class Overtime_UserCreatorTests
{
private OvertimeManager _sut;

[Test]
public void BeAbleToBeConstructed()
{
_sut = new OvertimeManager();
Assert.That(_sut, Is.InstanceOf<OvertimeManager>());
}

[Test]
public void BeAbleToBeConstructedUsingMoq()
{
var mockDatabase = new Mock<IndividualProject_DatabaseContext>();
_sut = new OvertimeManager(mockDatabase.Object);
Assert.That(_sut, Is.InstanceOf<OvertimeManager>());
}

[Test]
public void
}
}
92 changes: 46 additions & 46 deletions BusinessLayerTesting/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,40 @@ public void WhenUserNameDoesExist_EnteredUserShouldNotBeNullAndCreateDoesNotAddT
Assert.AreEqual(numberOfUsersAfter, numberOfUsersBefore);
}

[Test]
public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnMonday()
{
var useritems = overtimeManager.PopulateOvertimeForMonday();
Assert.AreEqual("Monday", useritems[0].Day);
}

[Test]
public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnTuesday()
{
var useritems = overtimeManager.PopulateOvertimeForTuesday();
Assert.AreEqual("Tuesday", useritems[0].Day);
}

[Test]
public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnWednesday()
{
var useritems = overtimeManager.PopulateOvertimeForWednesday();
Assert.AreEqual("Wednesday", useritems[0].Day);
}

[Test]
public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnThursday()
{
var useritems = overtimeManager.PopulateOvertimeForThursday();
Assert.AreEqual("Thursday", useritems[0].Day);
}

[Test]
public void WhenPopulateOvertimeFor_Friday_ThenOnlyPopulateListForAvailableOvertimesOnFriday()
{
var useritems = overtimeManager.PopulateOvertimeForFriday();
Assert.AreEqual("Friday", useritems[0].Day);
}
//[Test]
//public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnMonday()
//{
// var useritems = overtimeManager.PopulateOvertimeForMonday();
// Assert.AreEqual("Monday", useritems[0].Day);
//}

//[Test]
//public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnTuesday()
//{
// var useritems = overtimeManager.PopulateOvertimeForTuesday();
// Assert.AreEqual("Tuesday", useritems[0].Day);
//}

//[Test]
//public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnWednesday()
//{
// var useritems = overtimeManager.PopulateOvertimeForWednesday();
// Assert.AreEqual("Wednesday", useritems[0].Day);
//}

//[Test]
//public void WhenPopulateOvertimeFor_Monday_ThenOnlyPopulateListForAvailableOvertimesOnThursday()
//{
// var useritems = overtimeManager.PopulateOvertimeForThursday();
// Assert.AreEqual("Thursday", useritems[0].Day);
//}

//[Test]
//public void WhenPopulateOvertimeFor_Friday_ThenOnlyPopulateListForAvailableOvertimesOnFriday()
//{
// var useritems = overtimeManager.PopulateOvertimeForFriday();
// Assert.AreEqual("Friday", useritems[0].Day);
//}

[Test]
public void WhenSelectedItemIsBookedAndCancelIsClicked_ThenRemnoveTheUserIdConnectionToTheSelectedSlot()
Expand All @@ -107,21 +107,21 @@ public void WhenSelectedItemIsNotBookedAndBookIsClicked_ThenAddTheUserIdConnecti
Assert.AreEqual(overtimeManager.SelectedOvertime.UserId, user.UserId);
}

[Test]
public void WhenEnteredAdminIsInDatabase_AnAdminObjectIsReturnedWithTheirName()
{
var admin = adminManager.GetAdmin("Cathy");
Assert.AreEqual("Cathy", admin.AdminName);
//[Test]
//public void WhenEnteredAdminIsInDatabase_AnAdminObjectIsReturnedWithTheirName()
//{
// var admin = adminManager.GetAdmin("Cathy");
// Assert.AreEqual("Cathy", admin.AdminName);

}
//}

[Test]
public void WhenEnteredAdminIsNotInDatabase_NullIsReturned()
{
var admin = adminManager.GetAdmin("Dawood");
Assert.AreEqual(null, admin);
//[Test]
//public void WhenEnteredAdminIsNotInDatabase_NullIsReturned()
//{
// var admin = adminManager.GetAdmin("Dawood");
// Assert.AreEqual(null, admin);

}
//}

[Test]
public void WhenSelectedOvertimeOverlaps_FalseIsReturned()
Expand Down
7 changes: 7 additions & 0 deletions IP_Booking_Overtime/IP_Overtime.cd
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@
<Property Name="Users" />
</ShowAsCollectionAssociation>
</Class>
<Class Name="IP_Booking_Overtime.IndividualProject_DatabaseContext">
<Position X="6" Y="3.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAACAAAQAQAAAAAAAAAQAAEAAAAAAAAgAAAAAAAAA=</HashCode>
<FileName>IndividualProject_DatabaseContext.cs</FileName>
</TypeIdentifier>
</Class>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
5 changes: 4 additions & 1 deletion IP_BusinessLayer/IOvertimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

namespace IP_BusinessLayer
{
interface IOvertimeManager
public interface IOvertimeManager
{
public void CreateOvertime(string day, TimeSpan startTime, string numberOfHours);
public void RemoveOvertime(object selectedOvertime);
public void CreateOvertimeList(List<Overtime> overtimes);
public void GetSelectedOvertime(object selectedOvertime);
public Overtime GetOvertime(int overtimeId);
public void SetUser_IDs_ForBookedOvertime(Users enteredUser, object selectedOvertime);
public void RemoveUser_IDs_FromBookedOvertime(object selectedOvertime);
public List<Overtime> PopulateOvertimeForMonday();
Expand Down
11 changes: 11 additions & 0 deletions IP_BusinessLayer/IOvertimeUserCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace IP_BusinessLayer
{
public interface IOvertimeUserCreator
{
//public string Details(string userName, )
}
}
2 changes: 1 addition & 1 deletion IP_BusinessLayer/IUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace IP_BusinessLayer
{
interface IUserManager
public interface IUserManager
{
public List<Users> RetrieveUsers();
public void CreateUsers(List<Users> list);
Expand Down
66 changes: 48 additions & 18 deletions IP_BusinessLayer/OvertimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,34 @@ public void CreateOvertime(string day, TimeSpan startTime, string numberOfHours)
_db.SaveChanges();
}

public void GetSelectedOvertime(object selectedOvertime)
public void RemoveOvertime(object selectedOvertime)
{
GetSelectedOvertime(selectedOvertime);
if(SelectedOvertime != null)
{
_db.Overtime.Remove(SelectedOvertime);
_db.SaveChanges();
}
}

public void CreateOvertimeList(List<Overtime> overtimes)
{
_db.Overtime.AddRange(overtimes);
_db.SaveChanges();
}

public virtual void GetSelectedOvertime(object selectedOvertime)
{
SelectedOvertime = (Overtime)selectedOvertime;
}

public virtual Overtime GetOvertime(int id)
{
var selectedOvertime = _db.Overtime.Where(o => o.OvertimeId == id).FirstOrDefault();
GetSelectedOvertime(selectedOvertime);
return selectedOvertime;
}

public List<Overtime> PopulateAvailabelOvertime()
{
var available = _db.Overtime.Where(o => o.UserId == null);
Expand Down Expand Up @@ -99,28 +122,13 @@ public bool CheckForOverlap(Users enteredUser, object selectedOvertime)
{
GetSelectedOvertime(selectedOvertime);
var selectedOvertime_EndTime = SelectedOvertime.StartTime + TimeSpan.Parse($"{SelectedOvertime.NumberOfHours}:00");
var bookedOvertimes = _db.Overtime.Where(o => o.UserId == enteredUser.UserId);
var bookedOvertimes = PopulateBookedOvertime(enteredUser);
var canBook = true;
if (bookedOvertimes.Count() > 0)
{
TimeSpan? bookedOvertimeSlotEndTime;
foreach (var bookedOvertimeSlot in bookedOvertimes)
{
bookedOvertimeSlotEndTime = bookedOvertimeSlot.StartTime + TimeSpan.Parse($"{bookedOvertimeSlot.NumberOfHours}:00");
if (bookedOvertimeSlotEndTime < SelectedOvertime.StartTime)
{
if (!(bookedOvertimeSlotEndTime < SelectedOvertime.StartTime && bookedOvertimeSlot.StartTime < selectedOvertime_EndTime) && bookedOvertimeSlot.Day == SelectedOvertime.Day)
{
canBook = false;
}
}
else if (bookedOvertimeSlotEndTime > SelectedOvertime.StartTime)
{
if (!(bookedOvertimeSlotEndTime > SelectedOvertime.StartTime && bookedOvertimeSlot.StartTime > selectedOvertime_EndTime) && bookedOvertimeSlot.Day == SelectedOvertime.Day)
{
canBook = false;
}
}
canBook = CanBook(selectedOvertime_EndTime, bookedOvertimeSlot);
}
if (canBook)
{
Expand All @@ -133,5 +141,27 @@ public bool CheckForOverlap(Users enteredUser, object selectedOvertime)
}
return canBook;
}

private bool CanBook(TimeSpan? selectedOvertime_EndTime, Overtime bookedOvertimeSlot)
{
var canBook = true;
TimeSpan? bookedOvertimeSlotEndTime = bookedOvertimeSlot.StartTime + TimeSpan.Parse($"{bookedOvertimeSlot.NumberOfHours}:00");
if (bookedOvertimeSlotEndTime < SelectedOvertime.StartTime)
{
if (!(bookedOvertimeSlotEndTime < SelectedOvertime.StartTime && bookedOvertimeSlot.StartTime < selectedOvertime_EndTime) && bookedOvertimeSlot.Day == SelectedOvertime.Day)
{
canBook = false;
}
}
else if (bookedOvertimeSlotEndTime > SelectedOvertime.StartTime)
{
if (!(bookedOvertimeSlotEndTime > SelectedOvertime.StartTime && bookedOvertimeSlot.StartTime > selectedOvertime_EndTime) && bookedOvertimeSlot.Day == SelectedOvertime.Day)
{
canBook = false;
}
}

return canBook;
}
}
}
Loading

0 comments on commit 9342106

Please sign in to comment.