Esempio n. 1
0
        public void CheckAppUserToEditDetailsAreEqualLikeModel()
        {
            //Arrange
            AppUser appuser = new AppUser()
            {
                Id        = 6,
                FirstName = "test",
                LastName  = "unit",
                City      = "test"
            };

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

            var mock = new Mock <IAppUserRepository>();

            mock.Setup(s => s.GetAppUser(6)).Returns(appuser);

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

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

            //Assert
            result.Should().NotBeNull();
            result.Id.Should().Equals(appuser.Id);
            appuser.Id = 7;
            result.Id.Should().Equals(appuser.Id);
            result.FirstName.Should().Equals(appuser.FirstName);
            result.LastName.Should().Equals(appuser.LastName);
        }
Esempio n. 2
0
        public void CheckAppUserToEditDetailsAreEqualLikeModel()
        {
            //Arrange
            NewAppUserVm appUser = new NewAppUserVm()
            {
                Id         = 1,
                FirstName  = "test2",
                PositionId = 1
            };

            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 appUserService = new AppUserService(mapper, new AppUserRepository(context));
                appUserService.AddAppUser(appUser);
                var result = appUserService.GetAppUserForEdit(1);

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