public void DetachPackageFromEmployee_ForCorrectConditions_ShouldDetachPackageFromEmployee() { var package = new Package { Id = 1, Height = 100, Weight = 100, Width = 100, Length = 100, Status = PackageStatus.InWarehouse }; var employee = new Employee { Id = 1, FirstName = "A", LastName = "B" }; var mockContext = new Mock <InstantDeliveryContext>(); mockContext.Setup(c => c.Packages).ReturnsDbSet(package); mockContext.Setup(c => c.Employees).ReturnsDbSet(employee); mockContext.Setup(m => m.PackageEvents).ReturnsDbSet(new List <PackageEvent>()); var controller = new PackagesController(mockContext.Object, null); controller.AssignPackage(package.Id, employee.Id); controller.DetachPackageFromEmployee(package.Id); Assert.Equal(0, employee.Packages.Count); }
public void AssignPackage_AssignsPackageToEmployee() { var package = new Package { Id = 1, Height = 100, Weight = 100, Width = 100, Length = 100, Status = PackageStatus.InWarehouse }; var employee = new Employee { Id = 1, FirstName = "A", LastName = "B" }; var mockContext = new Mock <InstantDeliveryContext>(); mockContext.Setup(c => c.Packages).ReturnsDbSet(package); mockContext.Setup(c => c.Employees).ReturnsDbSet(employee); mockContext.Setup(m => m.PackageEvents).ReturnsDbSet(new List <PackageEvent>()); var controller = new PackagesController(mockContext.Object, null); controller.AssignPackage(package.Id, employee.Id); Assert.Equal(PackageStatus.InDelivery, package.Status); Assert.Equal(1, employee.Packages.Count); Assert.Equal(package, employee.Packages.First()); mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
public void AssignPackage_ShouldAddEventToPackageHistory() { var package = new Package { Id = 1, }; var employee = new Employee { Id = 1, FirstName = "A", LastName = "B" }; var mockSet = new Mock <IDbSet <PackageEvent> >(); var mockContext = new Mock <InstantDeliveryContext>(); mockContext.Setup(c => c.Packages).ReturnsDbSet(package); mockContext.Setup(c => c.Employees).ReturnsDbSet(employee); mockContext.Setup(c => c.PackageEvents).Returns(mockSet.Object); var controller = new PackagesController(mockContext.Object, null); controller.AssignPackage(package.Id, employee.Id); mockSet.Verify(m => m.Add(It.Is((PackageEvent pe) => pe.Package.Id == package.Id && pe.Employee.Id == employee.Id && pe.EventType == PackageEventType.HandedToCourier))); }