public void GetById_ShouldReturnEmployee()
        {
            var employee = new Employee { Id = 1, FirstName = "Ted", LastName = "Mosby" };
            var mockContext = new Mock<InstantDeliveryContext>();
            mockContext.Setup(c => c.Employees).ReturnsDbSet(employee);

            var userStore = new Mock<UserStore<User>>(mockContext.Object);
            var userManager = new Mock<UserManager<User>>(userStore.Object);
            var controller = new EmployeesController(mockContext.Object, userManager.Object);
            var result = (controller.Get(employee.Id) as OkNegotiatedContentResult<EmployeeDto>)?.Content;

            Assert.Equal(result?.FirstName, employee.FirstName);
            Assert.Equal(result?.LastName, employee.LastName);
            Assert.Equal(result?.Id, employee.Id);
        }
        public void ChangeEmployeesVehicle_ShouldChangeEmployeeVehicle()
        {
            var employee = new Employee { FirstName = "Ted", LastName = "Mosby", Id = 1 };
            var vehicle = new Vehicle { Id = 1 };

            var mockContext = new Mock<InstantDeliveryContext>();
            mockContext.Setup(c => c.Employees).ReturnsDbSet(employee);
            mockContext.Setup(c => c.Vehicles).ReturnsDbSet(vehicle);

            var userStore = new Mock<UserStore<User>>(mockContext.Object);
            var userManager = new Mock<UserManager<User>>(userStore.Object);
            var controller = new EmployeesController(mockContext.Object, userManager.Object);
            controller.ChangeVehicle(employee.Id, vehicle.Id);

            Assert.Equal(employee.Vehicle.Id, 1);
        }
        public void RemoveEmployee_ForDeliveredPackage_ShouldNotChangeItsStatus()
        {
            var package = new Package
            {
                Id = 1,
                Status = PackageStatus.Delivered
            };
            var employee = new Employee { Id = 1, FirstName = "Ted" };

            var mockContext = new Mock<InstantDeliveryContext>();
            mockContext.Setup(c => c.Packages).ReturnsDbSet(package);
            mockContext.Setup(c => c.Employees).ReturnsDbSet(employee);
            var userStore = new Mock<UserStore<User>>(mockContext.Object);
            var userManager = new Mock<UserManager<User>>(userStore.Object);
            var controller = new EmployeesController(mockContext.Object, userManager.Object);
            controller.Delete(employee.Id);

            Assert.Equal(PackageStatus.Delivered, package.Status);
        }
        public void RemoveEmployee_ForPackagesInDelivery_ShouldSetPackagesStatusBackToNew()
        {
            var package = new Package
            {
                Id = 1,
                Status = PackageStatus.InDelivery
            };
            var employee = new Employee { Id = 1, FirstName = "Ted", LastName = "Mosby" };
            employee.Packages.Add(package);

            var mockContext = new Mock<InstantDeliveryContext>();
            mockContext.Setup(c => c.Packages).ReturnsDbSet(package);
            mockContext.Setup(c => c.Employees).ReturnsDbSet(employee);

            var userStore = new Mock<UserStore<User>>(mockContext.Object);
            var userManager = new Mock<UserManager<User>>(userStore.Object);
            var controller = new EmployeesController(mockContext.Object, userManager.Object);
            controller.Delete(employee.Id);

            Assert.Equal(PackageStatus.InWarehouse, package.Status);
        }
        public void GetAssignedEmployee_ShouldReturnAssignedEmployee()
        {
            var package = new Package { Id = 1, Status = PackageStatus.InDelivery };
            var employee = new Employee { Id = 1 };
            employee.Packages.Add(package);
            var mockContext = GetEmptyMockContext();
            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);
            var response = controller.GetAssignedEmployee(package.Id) as OkNegotiatedContentResult<EmployeeDto>;

            Assert.NotNull(response);
            Assert.Equal(response.Content.Id, employee.Id);
        }
        public void MarkAsDelivered_ShouldAddEventToPackageHistory()
        {
            var package = new Package { Id = 1, Status = PackageStatus.InDelivery };
            var employee = new Employee { Id = 1 };
            employee.Packages.Add(package);

            var mockSet = new Mock<IDbSet<PackageEvent>>();
            var mockContext = GetEmptyMockContext();
            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.MarkAsDelivered(package.Id);

            mockSet.Verify(m => m.Add(It.Is((PackageEvent pe) => pe.Package.Id == package.Id &&
                                                                 pe.Employee.Id == employee.Id &&
                                                                 pe.EventType == PackageEventType.Delivered)));
        }
        public void MarkAsDelivered_ShouldRemovePackageFromEmployeeCollection()
        {
            var package = new Package { Id = 1, Status = PackageStatus.InDelivery };
            var employee = new Employee { Id = 1 };
            employee.Packages.Add(package);
            var mockContext = GetEmptyMockContext();
            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.MarkAsDelivered(package.Id);

            Assert.Equal(employee.Packages.Count, 0);
        }
        public void RemovePackage_ShouldRemovePackage()
        {
            var package = new Package
            {
                Id = 1,
                Status = PackageStatus.InDelivery
            };
            var packages = new List<Package> { package };
            var packagesMockSet = MockDbSetHelper.CreateMockSet(packages.AsQueryable());

            var employee = new Employee { Id = 1, FirstName = "A", LastName = "B" };

            var mockContext = new Mock<InstantDeliveryContext>();
            mockContext.Setup(c => c.Packages).Returns(packagesMockSet.Object);
            mockContext.Setup(c => c.Employees).ReturnsDbSet(employee);

            var controller = new PackagesController(mockContext.Object, null);
            controller.Delete(package.Id);

            packagesMockSet.Verify(m => m.Remove(It.Is((Package p) => p.Id == package.Id)), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
        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_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)));
        }
        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());
        }
 private string GenerateUserName(Employee employee)
 {
     string username = (employee.FirstName + employee.LastName).ToLower();
     username = username.ReplaceNationalCharacters();
     if (context.Users.Any(u => u.UserName == username))
     {
         int i = 1;
         while (context.Users.Any(u => u.UserName == username + i))
         {
             i++;
         }
         username = username + i;
     }
     return username;
 }
Beispiel #13
0
 /// <summary>
 /// Zwraca treść wiadomości HTML po przypisaniu paczki do kuriera.
 /// </summary>
 /// <param name="employee"></param>
 /// <returns></returns>
 public string AssignedPackageBody(Employee employee)
 {
     return @"Witaj " + employee.FirstName + " " + employee.LastName + " , " +
            "<br />Otrzymałeś nowe zlecenie. Sprawdź stan w systemie." +
            "</strong><em><br /><br />Pozdrawiamy, <br />Zespół Instant Delivery</em>";
 }
Beispiel #14
0
 /// <summary>
 /// Zwraca treść HTML wiadomomości po rejestracji.
 /// </summary>
 /// <param name="employee"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public string RegistrationBody(Employee employee, string password)
 {
     return @"Witaj " + employee.FirstName + " " + employee.LastName + " , " +
            "<br /><br />Twoje konto zostało zarejestrowane.<br />Nazwa użytkownika: <strong>"
            + employee.User.UserName + "</strong><br />" +
            "Hasło: <strong>" + password +
            "</strong><em><br /><br />Pozdrawiamy, <br />Zespół Instant Delivery</em>";
 }