public async Task HandleAsync_InputIsNormalQuery_ShouldReturnProperEmployee()
        {
            var database = new EmployeeManagementDbContext(Guid.NewGuid().ToString());

            database.Add(new DomainModel.Entities.Employee()
            {
                EmployeeId = Guid.Parse("00000000-0000-0000-0000-000000000000"),
                Name       = "TestName1",
                Position   = "TestPosition1",
            });
            database.Add(new DomainModel.Entities.Employee()
            {
                EmployeeId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Name       = "TestName2",
                Position   = "TestPosition2",
            });
            await database.SaveChangesAsync();

            var handler = new Application.Employee.ReadEmployeeById.Handler(database);
            var query   = new Application.Employee.ReadEmployeeById.Query()
            {
                EmployeeId = Guid.Parse("00000000-0000-0000-0000-000000000001")
            };

            var result = await handler.Handle(query, CancellationToken.None);

            Assert.AreEqual(Guid.Parse("00000000-0000-0000-0000-000000000001"), result.EmployeeId);
        }
        public async Task HandleAsync_InputIsNormalCommand_ShouldRecordHistory()
        {
            var database = new EmployeeManagementDbContext(Guid.NewGuid().ToString());

            database.Add(new DomainModel.Entities.Employee()
            {
                EmployeeId = Guid.Empty,
                Name       = "TestName",
                Position   = "TestPosition"
            });
            await database.SaveChangesAsync();

            var handler     = new Application.Employee.UpdateEmployee.Handler(database, GetDateTimeServiceMock());
            var newName     = "NewTestName";
            var newPosition = "NewTestPosition";
            var command     = new Application.Employee.UpdateEmployee.Command()
            {
                EmployeeId = Guid.Empty,
                Employee   = new DomainModel.Entities.Employee()
                {
                    Name     = newName,
                    Position = newPosition
                }
            };

            await handler.Handle(command, CancellationToken.None);

            var result  = database.Employees.FirstOrDefault(e => e.EmployeeId == Guid.Empty);
            var history = result.EditHistories[0];

            Assert.AreEqual(DateTime.MinValue, history.TimeStamp);
            Assert.AreEqual(newName, history.Name);
            Assert.AreEqual(newPosition, history.Position);
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Gender,Email,Department,Photo")] CreateViewModel createView)
        {
            if (ModelState.IsValid)
            {
                Employee NewEmployee = new Employee
                {
                    Name       = createView.Name,
                    Gender     = createView.Gender,
                    Department = createView.Department,
                    Email      = createView.Email,
                    PhotoPath  = await FileManagerService.SaveImage(createView.Photo)
                };
                _context.Add(NewEmployee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { Id = NewEmployee.Id }));
            }
            return(View(createView));
        }