Beispiel #1
0
        public async Task AddEmployeeAsyncTest_WithNullUserId_ShouldReturnArgumentNullException()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var service = new EmployeesService(repository, this.GetMockUserManager().Object);

            await repository.AddAsync(new SteuUser()
            {
                Id       = "asdasd",
                UserName = "******",
                Company  = new Company()
                {
                    Name = "Pesho Ltd",
                },
            });

            await repository.SaveChangesAsync();

            AddEmployeeInputModel model = new AddEmployeeInputModel()
            {
                FirstName       = "Gosho",
                LastName        = "Goshov",
                Username        = "******",
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******",
            };

            await Assert.ThrowsAsync <ArgumentNullException>(()
                                                             => service.AddEmployeeAsync(null, model));
        }
Beispiel #2
0
        public async Task AddEmployeeAsyncTest_WithCoreectData_ShouldReturnTrue()
        {
            var context = SteuDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();
            var repository = new EfDeletableEntityRepository <SteuUser>(context);

            var service = new EmployeesService(repository, this.GetMockUserManager().Object);

            await repository.AddAsync(new SteuUser()
            {
                Id       = "asdasd",
                UserName = "******",
                Company  = new Company()
                {
                    Name = "Pesho Ltd",
                },
            });

            await repository.SaveChangesAsync();

            AddEmployeeInputModel model = new AddEmployeeInputModel()
            {
                FirstName       = "Gosho",
                LastName        = "Goshov",
                Username        = "******",
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******",
            };

            var actualResult = await service.AddEmployeeAsync("asdasd", model);

            Assert.True(actualResult);
        }
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Gender,Birth,Address,Phone,Email,Department")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                /*
                 * _context.Add(employee);
                 * await _context.SaveChangesAsync();
                 */
                await EmployeesService.AddEmployeeAsync(employee);

                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }