Exemplo n.º 1
0
        public async Task Update_WhenUserIsValid_ReturnsUserDTO()
        {
            // Arrange
            var oldUser      = UserFixture.CreateValidUser();
            var userToUpdate = UserFixture.CreateValidUserDTO();
            var userUpdated  = _mapper.Map <User>(userToUpdate);

            var encryptedPassword = new Lorem().Sentence();

            _userRepositoryMock.Setup(x => x.GetAsync(oldUser.Id))
            .ReturnsAsync(() => oldUser);

            _rijndaelCryptographyMock.Setup(x => x.Encrypt(It.IsAny <string>()))
            .Returns(encryptedPassword);

            _userRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <User>()))
            .ReturnsAsync(() => userUpdated);

            // Act
            var result = await _sut.UpdateAsync(userToUpdate);

            // Assert
            result.Value.Should()
            .BeEquivalentTo(_mapper.Map <UserDTO>(userUpdated));
        }
        public void AddsBooksToExistingReadingList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("adds_book_to_existing_reading_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                ReadingList readingList = new ReadingListFixture().ReadingList();
                User        user        = new UserFixture().User();
                user.ReadingLists.Add(readingList);
                context.Users.Add(user);
                context.SaveChanges();

                SessionHelperStub     session    = new SessionHelperStub(user);
                ReadingListController controller = new ReadingListController(context, session);

                Book newBook = new BookFixture().Book();

                JsonResult  result         = controller.Put(readingList.ReadingListId, newBook) as JsonResult;
                List <Book> expectedResult = context.ReadingLists
                                             .Where(r => r.ReadingListId == readingList.ReadingListId)
                                             .FirstOrDefault()
                                             .Books;

                Assert.Equal(readingList, result.Value);
                Assert.Equal(4, context.Books.Count());
                Assert.Contains(newBook, expectedResult);
                Assert.Equal(4, readingList.Books[3].Ranking);
            }
        }
        public void DeletesAReadingList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("deletes_a_reading_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                User        user        = new UserFixture().User();
                ReadingList readingList = new ReadingListFixture().ReadingList();
                user.ReadingLists.Add(readingList);
                context.Users.Add(user);
                context.SaveChanges();

                SessionHelperStub     session    = new SessionHelperStub(user);
                ReadingListController controller = new ReadingListController(context, session);

                Guid readingListId = readingList.ReadingListId;

                var result = controller.Delete(readingList.ReadingListId);

                Assert.Equal(0, context.ReadingLists.Count());
                Assert.Equal(null, context.ReadingLists.Where(r => r.ReadingListId == readingListId).FirstOrDefault());
            }
        }
Exemplo n.º 4
0
        public async Task Create_WhenUserIsValid_ReturnsUserDTO()
        {
            // Arrange
            var userToCreate = UserFixture.CreateValidUserDTO();

            var encryptedPassword = new Lorem().Sentence();
            var userCreated       = _mapper.Map <User>(userToCreate);

            userCreated.SetPassword(encryptedPassword);

            _userRepositoryMock.Setup(x => x.GetAsync(
                                          It.IsAny <Expression <Func <User, bool> > >(),
                                          It.IsAny <bool>()))
            .ReturnsAsync(() => null);

            _rijndaelCryptographyMock.Setup(x => x.Encrypt(It.IsAny <string>()))
            .Returns(encryptedPassword);

            _userRepositoryMock.Setup(x => x.CreateAsync(It.IsAny <User>()))
            .ReturnsAsync(() => userCreated);

            // Act
            var result = await _sut.CreateAsync(userToCreate);

            // Assert
            result.Value.Should()
            .BeEquivalentTo(_mapper.Map <UserDTO>(userCreated));
        }
        public void CreatesNewReadingList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("returns_users_reading_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                User user = new UserFixture().User();
                context.Users.Add(user);
                context.SaveChanges();

                SessionHelperStub     session    = new SessionHelperStub(user);
                ReadingListController controller = new ReadingListController(context, session);

                ReadingList readingList = new ReadingList
                {
                    Title = "Existential Meltdown",
                    Books = new List <Book>()
                    {
                        new BookFixture().Book()
                    }
                };

                JsonResult result = controller.Post(readingList) as JsonResult;

                Assert.Equal(1, context.ReadingLists.Count());
                Assert.Equal(1, context.Books.Count());
                Assert.Equal(readingList, result.Value);
                Assert.Equal(1, readingList.Books[0].Ranking);
            }
        }
        public void ShowReturns401WhenUserDoesntOwnList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("show_returns_401")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                ReadingList readingList      = new ReadingListFixture().ReadingList();
                User        user             = new UserFixture().User();
                User        unauthorizedUser = new User
                {
                    Email  = "unauthorized test email",
                    Avatar = "unauthorized test avatar",
                };
                user.ReadingLists.Add(readingList);
                context.Users.AddRange(new List <User>()
                {
                    user, unauthorizedUser
                });
                context.SaveChanges();

                SessionHelperStub     session    = new SessionHelperStub(unauthorizedUser);
                ReadingListController controller = new ReadingListController(context, session);

                var result = controller.Get(readingList.ReadingListId);

                Assert.IsType <NotFoundResult>(result);
            }
        }
        public void PatchReordersAList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("patch_reorders_a_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                ReadingList readingList = new ReadingListFixture().ReadingList();
                User        user        = new UserFixture().User();
                user.ReadingLists.Add(readingList);
                context.Add(user);
                context.SaveChanges();

                Book book1 = readingList.Books[0];
                Book book2 = readingList.Books[1];
                Book book3 = readingList.Books[2];

                SessionHelperStub     session    = new SessionHelperStub(user);
                ReadingListController controller = new ReadingListController(context, session);

                PatchData data = new PatchData
                {
                    BookId  = book1.BookId,
                    Ranking = 2
                };

                JsonResult result = controller.Patch(readingList.ReadingListId, data) as JsonResult;

                Assert.Equal(2, book1.Ranking);
                Assert.Equal(1, book2.Ranking);
                Assert.Equal(3, book3.Ranking);
            }
        }
        protected override void FinalizeSetUp()
        {
            _fixture = FixtureRepository.Create<UserFixture>();

            RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings);

            RedisApiOutputCache.Add(_fixture.Id.ToString(), _fixture, DateTime.Now.AddSeconds(60));
        }
Exemplo n.º 9
0
        protected override void FinalizeSetUp()
        {
            _fixture = FixtureRepository.Create <UserFixture>();

            RedisApiOutputCache = new RedisOutputCache(new JsonSerializer(), _connectionSettings);

            RedisApiOutputCache.Add(_fixture.Id.ToString(), _fixture, DateTime.Now.AddSeconds(60));
        }
Exemplo n.º 10
0
        public LocalizationServiceTest(LocalizationFixture fixture, UserFixture userFixture)
        {
            this.fixture     = fixture;
            this.userFixture = userFixture;

            mockUserService = new Mock <IUserService>();
            service         = new LocalizationService(mockUserService.Object);
        }
Exemplo n.º 11
0
 public UserStoreTests(UserFixture <ApplicationUser, IdentityRole, IdentityCloudContext> userFix, ITestOutputHelper output)
 {
     Initialize();
     this.output = output;
     userFixture = userFix;
     userFixture.Init();
     CurrentUser      = userFix.CurrentUser;
     CurrentEmailUser = userFix.CurrentEmailUser;
 }
Exemplo n.º 12
0
        public async Task GetAllUsers_WhenUsersExists_ReturnsAListOfUserDTO()
        {
            // Arrange
            var usersFound = UserFixture.CreateListValidUser();

            _userRepositoryMock.Setup(x => x.GetAllAsync())
            .ReturnsAsync(() => usersFound);

            // Act
            var result = await _sut.GetAllAsync();

            // Assert
            result.Value.Should()
            .BeEquivalentTo(_mapper.Map <List <UserDTO> >(usersFound));
        }
Exemplo n.º 13
0
        public async Task GetById_WhenUserExists_ReturnsUserDTO()
        {
            // Arrange
            var userId    = new Randomizer().Int(0, 1000);
            var userFound = UserFixture.CreateValidUser();

            _userRepositoryMock.Setup(x => x.GetAsync(userId))
            .ReturnsAsync(() => userFound);

            // Act
            var result = await _sut.GetAsync(userId);

            // Assert
            result.Value.Should()
            .BeEquivalentTo(_mapper.Map <UserDTO>(userFound));
        }
        public ExchangeRateServiceTest(ExchangeRateFixture fixture, UserFixture userFixture)
        {
            this.fixture     = fixture;
            this.userFixture = userFixture;

            mockUserService = new Mock <IUserService>();
            mockApiService  = new Mock <IApiService>();
            mockCache       = new Mock <ObjectCache>();

            service = new ExchangeRateService(mockUserService.Object, mockApiService.Object, mockCache.Object);
            setupLoadConfiguration = new SetupLoadConfiguration
            {
                MockApi   = mockApiService,
                MockCache = mockCache
            };
        }
Exemplo n.º 15
0
        public async Task Update_WhenUserNotExists_ReturnsEmptyOptional()
        {
            // Arrange
            var userToUpdate = UserFixture.CreateValidUserDTO();

            _userRepositoryMock.Setup(x => x.GetAsync(
                                          It.IsAny <Expression <Func <User, bool> > >(),
                                          It.IsAny <bool>()))
            .ReturnsAsync(() => null);

            // Act
            var result = await _sut.UpdateAsync(userToUpdate);

            // Act
            result.HasValue.Should()
            .BeFalse();
        }
Exemplo n.º 16
0
        public async Task GetByEmail_WhenUserExists_ReturnsUserDTO()
        {
            // Arrange
            var userEmail = new Internet().Email();
            var userFound = UserFixture.CreateValidUser();

            _userRepositoryMock.Setup(x => x.GetAsync(
                                          It.IsAny <Expression <Func <User, bool> > >(),
                                          It.IsAny <bool>()))
            .ReturnsAsync(() => userFound);

            // Act
            var result = await _sut.GetByEmailAsync(userEmail);

            // Assert
            result.Value.Should()
            .BeEquivalentTo(_mapper.Map <UserDTO>(userFound));
        }
Exemplo n.º 17
0
        public async Task SearchByEmail_WhenAnyUserFound_ReturnsAListOfUserDTO()
        {
            // Arrange
            var emailSoSearch = new Internet().Email();
            var usersFound    = UserFixture.CreateListValidUser();

            _userRepositoryMock.Setup(x => x.SearchAsync(
                                          It.IsAny <Expression <Func <User, bool> > >(),
                                          It.IsAny <bool>()))
            .ReturnsAsync(() => usersFound);

            // Act
            var result = await _sut.SearchByEmailAsync(emailSoSearch);

            // Assert
            result.Value.Should()
            .BeEquivalentTo(_mapper.Map <List <UserDTO> >(usersFound));
        }
        public void ReturnsAReadingList()
        {
            var options = new DbContextOptionsBuilder <ReadingListApiContext>()
                          .UseInMemoryDatabase("returns_a_reading_list")
                          .Options;

            using (var context = new ReadingListApiContext(options))
            {
                User        user        = new UserFixture().User();
                ReadingList readingList = new ReadingListFixture().ReadingList();
                user.ReadingLists.Add(readingList);
                context.Users.Add(user);
                context.SaveChanges();

                SessionHelperStub     session    = new SessionHelperStub(user);
                ReadingListController controller = new ReadingListController(context, session);


                JsonResult result = controller.Get(readingList.ReadingListId) as JsonResult;

                Assert.Equal(readingList, result.Value);
            }
        }
Exemplo n.º 19
0
 public UserServiceTest(UserFixture fixture) : base(fixture)
 {
 }
Exemplo n.º 20
0
 public UserStoreTests(
     UserFixture <ApplicationUserV2, IdentityRole, IdentityCloudContext,
                  UserStore <ApplicationUserV2, IdentityRole, IdentityCloudContext>, DefaultKeyHelper> userFix, ITestOutputHelper output) :
     base(userFix, output)
 {
 }
Exemplo n.º 21
0
 static UserStoreTests()
 {
     //Look out, hack!
     userFixture = new UserFixture <ApplicationUser, IdentityRole, IdentityCloudContext>();
 }
 public UserOnlyStoreSHA256Tests(UserFixture <ApplicationUserV2, IdentityCloudContext, UserOnlyStore <ApplicationUserV2, IdentityCloudContext>, SHA256KeyHelper> userFix, ITestOutputHelper output) :
     base(userFix, output)
 {
 }
 public AuthenticationActionTestBase()
     : base()
 {
     this._users = new UserFixture(_client);
 }