Beispiel #1
0
        public void DeletedEmployerShoundNotExistInDatabase()
        {
            //Arrange
            NewEmployerVm employerToAdd = new NewEmployerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var employerService = new EmployerService(mapper, new EmployerRepository(context));
                var result          = employerService.AddEmployer(employerToAdd);
                employerService.DeleteEmployer(1);
                var deletedEmployer = employerService.GetEmployerDetails(1);

                //Assert
                deletedEmployer.Should().BeNull();
            }
        }
        public void CheckEmployerDetailsAreEqualLikeModel()
        {
            //Arrange
            Employer employer = new Employer()
            {
                Id   = 6,
                Name = "test",
                NIP  = "unit",
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var mock = new Mock <IEmployerRepository>();

            mock.Setup(s => s.GetEmployer(6)).Returns(employer);

            var manager = new EmployerService(mapper, mock.Object);

            //Act
            var result = manager.GetEmployerDetails(6);

            //Assert
            result.Should().NotBeNull();
            result.Id.Should().Equals(employer.Id);
            employer.Id = 7;
            result.Id.Should().Equals(employer.Id);
            result.Name.Should().Equals(employer.Name);
            result.NIP.Should().Equals(employer.NIP);
        }
Beispiel #3
0
        public void CheckEmployerDetailsAreEqualLikeModel()
        {
            //Arrange
            NewEmployerVm employerToAdd = new NewEmployerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit"
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;


            using (var context = new Context(options))
            {
                //Act
                var employerService = new EmployerService(mapper, new EmployerRepository(context));
                employerService.AddEmployer(employerToAdd);
                var result = employerService.GetEmployerDetails(1);

                //Assert
                result.Should().NotBeNull();
                result.Should().Equals(employerToAdd);
                context.Employers.FirstOrDefaultAsync(e => e.Id == result.Id).Should().NotBeNull();
            }
        }