Exemplo n.º 1
0
        public void TestSmokeEmail()
        {
            User user = usercreator.Create(login, password);

            //Login to the mail.ru
            HomePage  homePage  = new HomePage();
            InboxPage inboxPage = homePage.Login(user);

            //Assert a user is logged in
            Assert.IsTrue(inboxPage.IsSucessfullyLoggedIn(), "User is not logged in");

            //Create a new mail
            EmailPage emailPage = inboxPage.ClickCreateNewMessageButton();

            email = new DraftEmail(email);

            //Navigate to DraftsPage
            NavigationMenu navigationMenu = new NavigationMenu();
            DraftsPage     draftsPage     = navigationMenu.NavigateToDrafts();

            //Open Draft Email on DraftsPage
            emailPage = draftsPage.ClickDraftEmail(email);

            //Verify the draft content (addressee, subject and body – should be the same)
            Assert.IsTrue(emailPage.GetAddress().Equals(address), "Address is wrong.");
            Assert.IsTrue(emailPage.GetSubject().Equals(email.subject), "Message subject doesn't match");
            Assert.IsTrue(emailPage.GetMessage().Contains(expectedTestBody), "Message is incorrect.");

            //Send the mail
            emailPage.ClickSendEmailButton();

            // Verify the email is sent message
            //Assert.IsTrue(emailPage.GetVerificationMessage().Contains(ExpectedMessage));

            //Navigate to DraftsPage and verify, that the mail disappeared from ‘Drafts’ folder
            draftsPage = navigationMenu.NavigateToDrafts();
            draftsPage.WaitForEmailDisappearedBySubject(email.subject);
            Assert.IsFalse(draftsPage.IsEmailPresentBySubject(email.subject));

            //Navigate to SentPage
            SentPage sentPage = navigationMenu.NavigateToSent();

            //Verify, that the mail presents in ‘Sent’ folder.
            sentPage.WaitForEmailinSentFolder(subject);
            Assert.IsTrue(sentPage.IsEmailPresentBySubject(email.subject));

            //Log out
            navigationMenu.LogOut();
        }
Exemplo n.º 2
0
        public async Task ApproveAsyncShould_ReturnsTrue_IfManagerRegionIsEqualToIssueRegion_OrManagerIsForAllRegionsAnd_SetsIssuePropertyIsApprovedToTrue()
        {
            //Arrange
            var manager = UserCreator.Create(RegionType.Western);
            await Db.AddAsync(manager);

            var issue = UrbanIssueCreator.CreateIssue(RegionType.Western, DefaultImageId);
            await Db.AddAsync(issue);

            await Db.SaveChangesAsync();

            var activityService = new Mock <IManagerActivityService>();

            var service = new ManagerIssueService(Db, null, activityService.Object);

            //Act
            var result = await service.ApproveAsync(manager, issue.Id);

            var dbEntryIsApproved = this.Db.UrbanIssues.FirstOrDefault(i => i.Id == issue.Id)?.IsApproved;

            //Assert
            result.Should().BeTrue();

            dbEntryIsApproved.Should().BeTrue();

            activityService.Verify(a =>
                                   a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Once);
        }
Exemplo n.º 3
0
        public async Task AllAsyncShould_ReturnsAllManagersActivitySorted()
        {
            //Arrange
            var manager       = UserCreator.Create();
            var secondManager = UserCreator.Create();

            await this.Db.AddRangeAsync(manager, secondManager);

            var managerLogs       = ManagerLogCreator.Create(manager.Id);
            var secondManagerLogs = ManagerLogCreator.Create(secondManager.Id);

            await this.Db.AddRangeAsync(managerLogs);

            await this.Db.AddRangeAsync(secondManagerLogs);

            await this.Db.SaveChangesAsync();

            var service = new ManagerActivityService(Db);

            //Act
            var result = (await service.AllAsync <ManagerActivitiesListingModel>()).ToList();

            var expectedCount = await this.Db.ManagerLogs
                                .CountAsync();

            //Assert
            result.Should().NotBeNull();
            result.Should().AllBeOfType <ManagerActivitiesListingModel>();
            result.Should().BeInDescendingOrder(x => x.DateTime);
            result.Should().HaveCount(expectedCount);
        }
        [Fact] // 5. public async Task<ManagedHomeInfoServiceModel> GetManagedDetailsAsync(string id)
        public async void GetManagedDetailsAsync_WithGivenListingId_ShouldReturnManagedListingModel()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home1.Owner = UserCreator.Create("Kanalin", "Tsolov", "tsola", "*****@*****.**");

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home4, home5);

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result = await service.GetManagedDetailsAsync(home1.Id);

            var expectedCount = this.Context.Homes
                                .Where(h => h.Id == home1.Id)
                                .Count();

            // Assert
            result.Should().BeOfType <ManagedHomeInfoServiceModel>();
            result.Owner.Should().Match(string.Format(OwnerFullName, home1.Owner.FirstName, home1.Owner.LastName));
        }
Exemplo n.º 5
0
        public void GetAlbumPhotos_ShouldReturnAllPhotosWhenUserIsOwner()
        {
            var user         = UserCreator.Create("test");
            var publicPhoto  = PhotoCreator.Create(user, false, false);
            var privatePhoto = PhotoCreator.Create(user, true, false);
            var album        = AlbumCreator.Create(false, user);

            var listAlbums = new List <Album>()
            {
                album
            };
            var listPhotoAlbums = new List <PhotoAlbum>()
            {
                PhotoAlbumCreator.Create(publicPhoto, album),
                PhotoAlbumCreator.Create(privatePhoto, album),
            };

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(listPhotoAlbums);
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(listAlbums);

            var service = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object);
            var photos  = service.GetAlbumPhotos <PhotoAlbumViewModel>(album.Id, user.Id);

            Assert.Equal(2, photos.Count);
        }
Exemplo n.º 6
0
        public async Task AddToRoleAsyncShould_ReturnsTrueWhen_UserIsNotInRole()
        {
            const string Role = "Manager";

            //Arrange
            var admin = UserCreator.Create();
            var user  = UserCreator.Create();

            await Db.Users.AddRangeAsync(admin, user);

            await Db.SaveChangesAsync();

            var userManagerMock = UserManagerMock.New;

            userManagerMock.Setup(u => u.FindByIdAsync(user.Id)).Returns(Task.FromResult(user));
            userManagerMock.Setup(u => u.IsInRoleAsync(user, Role)).Returns(Task.FromResult(false));

            var activityService = new Mock <IAdminActivityService>();

            //TODO: rewrite this test (now there is no need for userManager)
            var service = new AdminUserService(Db, activityService.Object);

            //Act
            var result = await service.AddToRoleAsync(admin.Id, user.Id, Role);

            //Assert
            result.Should().BeTrue();

            activityService.Verify(a =>
                                   a.WriteInfoAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), AdminActivityType.AddedToRole), Times.Once);
        }
Exemplo n.º 7
0
        public async Task WriteToDbAsyncShould_WriteInDbCorrectInfoForPicture()
        {
            const string PictureUrl          = "PicUrl";
            const string PictureThumbnailUrl = "picThumbnailUrl";
            const string PicturePublicId     = "PublicId";
            long         picLength           = long.MaxValue;
            DateTime     uploadedOn          = DateTime.UtcNow;

            //Arrange
            var service = new PictureInfoWriterService(this.Db);

            var user = UserCreator.Create();

            await this.Db.AddAsync(user);

            await this.Db.SaveChangesAsync();

            //Act
            var result = await service.WriteToDbAsync(user.Id, PictureUrl, PictureThumbnailUrl, PicturePublicId, uploadedOn, picLength);

            //Assert
            result.Should().BeOfType(typeof(int));

            var entry = this.Db.Find <CloudinaryImage>(result);

            entry.Id.Should().Be(result);
            entry.Length.Should().Be(picLength);
            entry.PicturePublicId.Should().Match(PicturePublicId);
            entry.PictureUrl.Should().Match(PictureUrl);
            entry.PictureThumbnailUrl.Should().Match(PictureThumbnailUrl);
            entry.UploadedOn.Should().Be(uploadedOn);
            entry.UploaderId.Should().Match(user.Id);
        }
        public async Task DeleteAsyncShould_ReturnsTrueIf_EventCreatorIsAnotherUser_AndShouldDeleteArticle_AndImage()
        {
            //Arrange
            var picServiceMock = IPictureServiceMock.New(imageToDeleteId);

            var service = new BlogArticleService(Db, null, picServiceMock.Object);

            var author = UserCreator.Create();

            await this.Db.AddAsync(author);

            var image = ImageInfoCreator.CreateWithFullData(author.Id);

            await this.Db.AddAsync(image);

            var article = ArticleCreator.Create(author.Id, imageToDeleteId);

            await this.Db.AddAsync(article);

            await this.Db.SaveChangesAsync();

            //Act
            var result = await service.DeleteAsync(article.Id, author.Id);

            //Assert
            result.Should().BeTrue();

            picServiceMock.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Once);

            this.Db.Articles.Should().NotContain(a => a.Id == article.Id);
        }
        public async Task DeleteAsyncShould_ReturnsFalseIf_EventCreatorIsAnotherUser_And_ShouldNotDeleteArticle_AndImage()
        {
            const string anotherAuthorId = "899f4fgg5f57dm888m";

            //Arrange
            var picServiceMock = IPictureServiceMock.New(imageToDeleteId);

            var service = new BlogArticleService(Db, null, picServiceMock.Object);

            var author = UserCreator.Create();

            await this.Db.AddAsync(author);

            var article = ArticleCreator.Create(author.Id, null);

            await this.Db.AddAsync(article);

            await this.Db.SaveChangesAsync();

            //Act
            var result = await service.DeleteAsync(article.Id, anotherAuthorId);

            //Assert
            result.Should().BeFalse();

            picServiceMock.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Never);

            this.Db.Articles.Should().Contain(a => a.Id == article.Id);
        }
        public async Task UpdateAsyncShould_UpdateTheCorrectPropertiesAnd_ShouldReturnsTrueIf_EventCreatorIsTheSame()
        {
            //Arrange
            var htmlService = IHtmlServiceMock.New(ContentForUpdate);

            var service = new BlogArticleService(Db, htmlService.Object, null);

            var author = UserCreator.Create();

            await this.Db.AddAsync(author);

            var article = ArticleCreator.Create(author.Id, null);

            await this.Db.AddAsync(article);

            await this.Db.SaveChangesAsync();

            //Act
            var result = await service.UpdateAsync(article.Id, author.Id, TitleForUpdate, ContentForUpdate);

            var updatedEntry = await Db.FindAsync <Article>(article.Id);

            //Assert
            result.Should().BeTrue();

            htmlService.Verify(h => h.Sanitize(It.IsAny <string>()), Times.Once);

            Assert.Equal(updatedEntry.Title, TitleForUpdate);
            Assert.Equal(updatedEntry.Content, ContentForUpdate);
        }
        public async Task UpdateAsyncShould_ReturnsFalseIf_EventCreatorIsAnotherUser()
        {
            const string UpdaterId = "789io87714w78ex5";

            //Arrange
            var htmlServiceMock = IHtmlServiceMock.New(ContentForUpdate);

            var service = new BlogArticleService(Db, htmlServiceMock.Object, null);

            var author = UserCreator.Create();

            await this.Db.AddAsync(author);

            var article = ArticleCreator.Create(author.Id, null);

            await this.Db.AddAsync(article);

            await this.Db.SaveChangesAsync();

            //Act
            var result = await service.UpdateAsync(article.Id, UpdaterId, TitleForUpdate, ContentForUpdate);

            //Assert
            result.Should().BeFalse();

            htmlServiceMock.Verify(h => h.Sanitize(It.IsAny <string>()), Times.Never);
        }
Exemplo n.º 12
0
        public async Task TotalAsyncShould_ReturnsCorrectCountOf_AllApprovedAnd_CountOfAllNotApprovedIssues(bool takeApproved)
        {
            //Arrange
            //TODO: rearrange test - now issueService has more parameters
            var service = new IssueService(this.Db, null);

            var user = UserCreator.Create();

            await this.Db.AddAsync(user);

            var image = ImageInfoCreator.CreateWithFullData(user.Id);

            await this.Db.AddRangeAsync(image);

            var issue       = CreateIssue(true, RegionType.Central, user.Id, image.Id);
            var secondIssue = CreateIssue(true, RegionType.Eastern, user.Id, image.Id);

            await this.Db.AddRangeAsync(issue, secondIssue);

            var notApprovedIssue       = CreateIssue(false, RegionType.North, user.Id, image.Id);
            var secondNotApprovedIssue = CreateIssue(true, RegionType.North, user.Id, image.Id);

            await this.Db.AddRangeAsync(notApprovedIssue, secondNotApprovedIssue);

            await this.Db.SaveChangesAsync();

            //Act
            var resultCount = await service.TotalAsync(isApproved : takeApproved);

            var expectedCount = await this.Db.UrbanIssues.Where(i => i.IsApproved == takeApproved).CountAsync();

            //Assert
            resultCount.Should().Be(expectedCount);
        }
Exemplo n.º 13
0
        public async Task UpdateAsyncShould_ReturnsTrue_IfManagerForAllRegionsUpdatesIssue_WithPictureFile()
        {
            //Arrange
            var pictureService = IPictureServiceMock.New(DefaultImageId);

            var activityService = new Mock <IManagerActivityService>();

            var service = new ManagerIssueService(
                Db, pictureService.Object, activityService.Object);

            var manager = UserCreator.Create(RegionType.All);
            await Db.AddAsync(manager);

            var issue = UrbanIssueCreator.CreateIssue(RegionType.Western);
            await Db.AddAsync(issue);

            await Db.SaveChangesAsync();

            var pictureFile = new Mock <IFormFile>();

            //Act
            var result = await service.UpdateAsync(
                manager, issue.Id, null, null, issue.Region, IssueType.DamagedRoads, null, pictureFile : pictureFile.Object);

            //Assert
            result.Should().BeTrue();

            pictureService.Verify(p => p.UploadImageAsync(It.IsAny <string>(), It.IsAny <IFormFile>()), Times.Once);

            pictureService.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Once);

            activityService.Verify(a => a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Once);
        }
Exemplo n.º 14
0
        public async Task RemoveResolvedReferenceAsyncShould_SettsIssuePropertyResolvedIssueToNull()
        {
            //Arrange
            var service = new ManagerIssueService(Db, null, null);

            var user = UserCreator.Create(null);
            await Db.AddAsync(user);

            var pic = ImageInfoCreator.Create();
            await Db.AddAsync(pic);

            var issue = UrbanIssueCreator.CreateIssue(true, RegionType.Western, user.Id, pic.Id);
            await Db.AddAsync(issue);

            var resolved = ResolvedCreator.Create(user.Id, issue.Id, pic.Id);

            await Db.AddAsync(resolved);

            var hasResolvedBefore = issue.ResolvedIssue != null; //true

            //Act
            await service.RemoveResolvedReferenceAsync(issue.Id);

            var hasResolvedAfter = issue.ResolvedIssue != null; //false

            //Assert
            hasResolvedAfter.Should().BeFalse();

            hasResolvedAfter.Should().IsSameOrEqualTo(!hasResolvedBefore);
        }
        public void AddPhoto_ShouldThrowErrorWhenPhotoAlreadyInTheAlbum()
        {
            var user    = UserCreator.Create("test");
            var photo   = PhotoCreator.Create(user, false, false);
            var album   = AlbumCreator.Create(false, user);
            var mapping = PhotoAlbumCreator.Create(photo, album);
            var list    = new List <PhotoAlbum>()
            {
                mapping
            };

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(list);
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(new List <Album>()
            {
                album
            });
            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });

            var       service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object);
            Exception ex      = Assert.Throws <AggregateException>(() => service.AddPhotoAsync(album.Id, photo.Id, user.Id).Wait());

            Assert.Contains("Photo is already added to the album", ex.Message);
        }
Exemplo n.º 16
0
        public async Task DeleteAsyncShould_DeletesCorrectCommentIf_CommentIdExists()
        {
            //Arrange
            var user = UserCreator.Create();

            this.db.Add(user);

            var article = ArticleCreator.Create(user.Id);

            this.db.Add(article);

            var comment       = this.CreateArticleComment(article.Id, user.Id);
            var secondComment = this.CreateArticleComment(article.Id, user.Id);

            this.db.AddRange(comment, secondComment);

            await this.db.SaveChangesAsync();

            var service = new ArticleCommentService(this.db);

            var commentsCount = this.db.Comments.Count();

            //Act
            var result = await service.DeleteAsync(comment.Id);

            //Assert
            result.Should().BeTrue();

            this.db.Comments.Count().Should().Be(commentsCount - 1);

            this.db.Find <Comment>(comment.Id).Should().BeNull();
        }
Exemplo n.º 17
0
        public static void ChangeUser(UserLevel maxLevel)
        {
            UserStore   userStore = new UserStore();
            UserCreator creator   = new UserCreator();

            Console.Clear();
            Console.WriteLine("Tryck enter för att avbryta");
            string userName = UserInput.GetInput <string>("Ange användarnamn att redigera:");

            if (userName == string.Empty)
            {
                return;
            }

            User user = userStore.FindById(userName);

            if (user == null)
            {
                Console.WriteLine("Användaren finns inte");
                UserInput.WaitForContinue();
                return;
            }

            if (user.UserLevel < maxLevel)
            {
                Console.WriteLine($"Kan ej redigera användarnivån {user.UserLevel}");
                UserInput.WaitForContinue();
                return;
            }

            creator.Create(userStore, user);
        }
Exemplo n.º 18
0
        public async Task SubmitAsyncShould_SetsTheCorrectPropsAnd_SavesEntityInDB()
        {
            const string commentContent = "Content";

            //Arrange
            var user = UserCreator.Create();

            this.db.Add(user);

            var article = ArticleCreator.Create(user.Id);

            this.db.Add(article);

            await this.db.SaveChangesAsync();

            var service = new ArticleCommentService(this.db);

            //Act
            var result = await service.SubmitAsync <CommentListingModel>(article.Id, user.Id, commentContent);

            result.Should().BeOfType <CommentListingModel>();

            result.ArticleAuthor.Should().BeEquivalentTo(user.UserName);

            result.ArticleId.Should().Be(article.Id);

            result.Id.Should().Be(result.Id);
        }
        public void GetUserFavoritePhotos_ShouldReturnFavoritePhotos()
        {
            var user    = UserCreator.Create("test");
            var visitor = UserCreator.Create("visitor");
            var photo1  = PhotoCreator.Create(user, false, false);
            var photo2  = PhotoCreator.Create(user, false, false);
            var photo3  = PhotoCreator.Create(visitor, false, false);

            var favorites = new List <PhotoFavorite>()
            {
                PhotoFavoriteCreator.Create(photo1, visitor),
                PhotoFavoriteCreator.Create(photo2, visitor),
                PhotoFavoriteCreator.Create(photo3, user),
            };

            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo1, photo2, photo3
            });
            var favoritesRepo = EfRepositoryMock.Get <PhotoFavorite>(favorites);

            var service          = new FavoritesService(favoritesRepo.Object, photosRepo.Object);
            var userFavorites    = service.GetUserFavoritePhotos <PhotoViewModel>(user.Id);
            var visitorFavorites = service.GetUserFavoritePhotos <PhotoViewModel>(visitor.Id);

            Assert.Single(userFavorites);
            Assert.Equal(2, visitorFavorites.Count);
        }
Exemplo n.º 20
0
        public async Task GetAsyncShould_ReturnsCorrectModel()
        {
            //Arrange
            var user = UserCreator.Create();

            this.db.Add(user);

            var article = ArticleCreator.Create(user.Id);

            this.db.Add(article);

            var comment = this.CreateArticleComment(article.Id, user.Id);

            this.db.Add(comment);

            await this.db.SaveChangesAsync();

            var service = new ArticleCommentService(this.db);

            //Act
            var result = await service.GetAsync <CommentListingModel>(article.Id);

            //Assert
            result.Should().BeOfType <CommentListingModel>();
            result.Id.Should().Be(article.Id);
        }
Exemplo n.º 21
0
        public void TestUpdateUserProfileProperties()
        {
            // given:
            User           user           = UserCreator.Create();
            User           userToUpdate   = UserDao.Get(user.Id);
            UserContactDto userContactDto = UserCreator.CreateUserContactDto("*****@*****.**",
                                                                             "Nürnberger Ei",
                                                                             "0",
                                                                             "01067",
                                                                             "Dresden",
                                                                             Country.DE,
                                                                             "Nürnberger Eieruhren GmbH",
                                                                             "http://www.nuernberger-eier.de",
                                                                             "phone",
                                                                             "privat",
                                                                             "mobile");
            UserDataDto                userDataDto      = UserCreator.CreateUserDataDto("neuerVorname", "neuerNachname", new DateTime(1990, 01, 03), "UserName");
            UserPaymentDto             userPaymentDto   = new UserPaymentDto("paypal", true);
            UserNotificationOptionsDto notificationsDto = UserNotificationOptionsDto.AllOn;
            User             changedBy        = UserCreator.Create();
            EntityChangedDto entityChangedDto = new EntityChangedDto(changedBy, new DateTime(2017, 01, 01, 01, 01, 01));

            // when:
            userToUpdate.Update(userContactDto, userDataDto, userPaymentDto, notificationsDto, entityChangedDto);
            UserDao.FlushAndClear();
            User actualUser = UserDao.Get(userToUpdate.Id);

            // then:
            DtoAssert.AreEqual(userContactDto, actualUser.GetUserContactDto());
            DtoAssert.AreEqual(userDataDto, actualUser.GetUserDataDto());

            actualUser.ChangedBy.Should().Be(entityChangedDto.ChangedBy);
            actualUser.ChangedAt.Should().Be(entityChangedDto.ChangedAt);
        }
Exemplo n.º 22
0
        public async Task DeleteImageAsyncShould_DeleteTheImageFromCloudAnd_ImageInfoFromDB()
        {
            //Arrange
            var cloudService = new Mock <ICloudImageService>();

            cloudService.Setup(cs => cs.UploadFormFileAsync(It.IsAny <IFormFile>()))
            .Returns(It.IsAny <Task <ImageUploadResult> >());

            var picInfoWriter = new Mock <IPictureInfoWriterService>();

            var service = new PictureService(this.Db, cloudService.Object, picInfoWriter.Object);

            var user = UserCreator.Create();

            await this.Db.AddAsync(user);

            var image = ImageInfoCreator.CreateWithFullData(user.Id);

            await this.Db.AddAsync(image);

            await this.Db.SaveChangesAsync();

            //Act
            await service.DeleteImageAsync(image.Id);

            //Assert
            cloudService.Verify(c => c.DeleteImages(It.IsAny <string>()), Times.Once);

            this.Db.CloudinaryImages
            .FirstOrDefault(i => i.Id == DefaultImageId).Should().BeNull();
        }
Exemplo n.º 23
0
        public async Task RemoveFromRoleAsyncShould_ReturnsFalseWhen_UserIsNotInRole()
        {
            const string Role = "Manager";

            //Arrange
            var admin = UserCreator.Create();
            var user  = UserCreator.Create();

            await Db.Users.AddRangeAsync(admin, user);

            await Db.SaveChangesAsync();

            var userManagerMock = UserManagerMock.New;

            userManagerMock.Setup(u => u.FindByIdAsync(user.Id)).Returns(Task.FromResult(user));
            userManagerMock.Setup(u => u.IsInRoleAsync(user, Role)).Returns(Task.FromResult(false));

            //TODO: rewrite this test (now there is no need for userManager)
            var service = new AdminUserService(Db, null);

            //Act
            var result = await service.RemoveFromRoleAsync(admin.Id, user.Id, Role);

            //Assert
            result.Should().Be(false);
        }
        public void RemovPhoto_ShouldRemoveSuccessfully()
        {
            var user    = UserCreator.Create("test");
            var photo   = PhotoCreator.Create(user, false, false);
            var album   = AlbumCreator.Create(false, user);
            var mapping = PhotoAlbumCreator.Create(photo, album);
            var list    = new List <PhotoAlbum>()
            {
                mapping
            };

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(list);
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(new List <Album>()
            {
                album
            });
            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });

            var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object);

            service.RemovePhotoAsync(album.Id, photo.Id, user.Id).Wait();

            Assert.Empty(list);
        }
Exemplo n.º 25
0
        public void Update_ShouldUpdateAlbumSucessfully()
        {
            var user  = UserCreator.Create("test");
            var album = AlbumCreator.Create(false, user);
            var list  = new List <Album>()
            {
                album,
            };

            var editAlbumModel = new EditAlbumInputModel
            {
                Id          = album.Id,
                OwnerId     = user.Id,
                Description = "Updated",
                IsPrivate   = false,
                Name        = "Updated",
            };

            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>());
            var albumsRepo      = DeletableEntityRepositoryMock.Get <Album>(list);

            var services = new AlbumsService(albumsRepo.Object, photoAlbumsRepo.Object);

            services.UpdateAsync(
                album.Id,
                user.Id,
                editAlbumModel).Wait();

            var item = list.First();

            Assert.Equal(editAlbumModel.Description, item.Description);
            Assert.Equal(editAlbumModel.Name, item.Name);
        }
        public void GetAllUsedAlbums_ShouldReturnCorrectNumber()
        {
            var user    = UserCreator.Create("test");
            var album1  = AlbumCreator.Create(false, user);
            var album2  = AlbumCreator.Create(false, user);
            var album3  = AlbumCreator.Create(false, user);
            var photo   = PhotoCreator.Create(user, false, false);
            var mapping = PhotoAlbumCreator.Create(photo, album1);

            var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(new List <Album>()
            {
                album1, album2, album3
            });
            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>()
            {
                mapping
            });

            var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object);
            var result  = service.GetAllUsedAlbums <AlbumViewModel>(photo.Id, user.Id);

            Assert.Single(result);
        }
        [Fact] // 2. public async Task<IEnumerable<ManagerDashboardPropertiesServiceModel>> GetManagedPropertiesAsync(string Id)
        public async void GetManagedPropertiesAsync_ShouldReturnAllManagedProperties()
        {
            // Arrange
            var ownerId = Guid.NewGuid().ToString();
            var country = CountryCreator.Create();
            var city    = CityCreator.Create(country.Id);

            var home1 = HomeCreator.CreateManagedHome(ownerId, city.Id);
            var home4 = HomeCreator.CreateAny(city.Id);
            var home5 = HomeCreator.CreateAny(city.Id);

            home1.Owner = UserCreator.Create("Kanalin", "Tsolov", "tsola", "*****@*****.**");

            await this.Context.Countries.AddAsync(country);

            await this.Context.Cities.AddAsync(city);

            await this.Context.Homes.AddRangeAsync(home1, home4, home5);

            await this.Context.SaveChangesAsync();

            var service = new ListingService(this.Context);

            // Act
            var result        = (await service.GetManagedPropertiesAsync(home1.ManagerId)).ToList();
            var expectedCount = this.Context.Homes
                                .Where(h => h.Status == HomeStatus.Managed && h.ManagerId == home1.ManagerId)
                                .Count();

            // Assert
            result.Should().AllBeOfType <ManagerDashboardPropertiesServiceModel>();
            result.Should().HaveCount(expectedCount);
            result.Should().HaveCount(1, "Because there is 1 managed home by this manager");
        }
        public void GetAllByPhotoId_ShouldReturnCorrectNumber()
        {
            var user     = UserCreator.Create("test");
            var album1   = AlbumCreator.Create(false, user);
            var album2   = AlbumCreator.Create(false, user);
            var album3   = AlbumCreator.Create(false, user);
            var photo    = PhotoCreator.Create(user, false, false);
            var mapping1 = PhotoAlbumCreator.Create(photo, album1);
            var mapping2 = PhotoAlbumCreator.Create(photo, album2);
            var mapping3 = PhotoAlbumCreator.Create(photo, album3);

            var albumsRepo = DeletableEntityRepositoryMock.Get <Album>(new List <Album>()
            {
                album1, album2, album3
            });
            var photosRepo = DeletableEntityRepositoryMock.Get <Photo>(new List <Photo>()
            {
                photo
            });
            var photoAlbumsRepo = EfRepositoryMock.Get <PhotoAlbum>(new List <PhotoAlbum>()
            {
                mapping1, mapping2, mapping3
            });

            var service = new PhotoAlbumService(photosRepo.Object, albumsRepo.Object, photoAlbumsRepo.Object);
            var result  = service.GetAllByPhotoId <PhotoAlbumViewModel>(photo.Id);

            Assert.Equal(3, result.Count);
        }
Exemplo n.º 29
0
        public async Task WriteLogInfoAsyncShould_SaveInDbCorrectInfo(ManagerActivityType actType)
        {
            //Arrange
            var manager = UserCreator.Create();

            await this.Db.AddAsync(manager);

            await this.Db.SaveChangesAsync();

            var service = new ManagerActivityService(this.Db);

            //Act

            var result = await service.WriteLogAsync(manager.Id, actType);

            var logFromDb = await this.Db.FindAsync <ManagerLog>(result);

            //Assert

            result.Should().BeOfType(typeof(int));

            logFromDb.Id.Should().Be(result);

            logFromDb.Activity.Should().Be(actType);

            logFromDb.ManagerId.Should().Match(manager.Id);

            logFromDb.DateTime.Should().BeLessThan(TimeSpan.FromSeconds(10));
        }
Exemplo n.º 30
0
        public async Task DeleteAsyncShould_ReturnsFalse_IfManagerRegionIsNotEqualToIssueRegion()
        {
            //Arrange
            var pictureService = IPictureServiceMock.New(DefaultImageId);

            var activityService = new Mock <IManagerActivityService>();

            var service = new ManagerIssueService(Db, pictureService.Object, activityService.Object);

            var manager = UserCreator.Create(RegionType.Central);
            await Db.AddAsync(manager);

            var issue = UrbanIssueCreator.CreateIssue(RegionType.Western);
            await Db.AddAsync(issue);

            await Db.SaveChangesAsync();

            //Act
            var result = await service.DeleteAsync(manager.Id, manager.ManagedRegion, issue.Id);

            //Assert
            result.Should().BeFalse();

            pictureService.Verify(p => p.DeleteImageAsync(It.IsAny <int>()), Times.Never);

            activityService.Verify(a =>
                                   a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Never);
        }