Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public async Task AllAsyncShould_ReturnsApprovedAndNotApprovedIssuesWith_CorrectModel(bool isApproved, RegionType concreteRegion)
        {
            //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);
            var secondIssue  = UrbanIssueCreator.CreateIssue(true, RegionType.Thracia, user.Id, pic.Id);
            var thirdIssue   = UrbanIssueCreator.CreateIssue(false, RegionType.Western, user.Id, pic.Id);
            var fourthIssue  = UrbanIssueCreator.CreateIssue(false, RegionType.North, user.Id, pic.Id);
            var fifthIssue   = UrbanIssueCreator.CreateIssue(false, RegionType.Thracia, user.Id, pic.Id);
            var sixthIssue   = UrbanIssueCreator.CreateIssue(false, RegionType.Western, user.Id, pic.Id);
            var seventhIssue = UrbanIssueCreator.CreateIssue(true, RegionType.South, user.Id, pic.Id);
            await Db.UrbanIssues.AddRangeAsync(issue, secondIssue, thirdIssue, fourthIssue, fifthIssue, sixthIssue, seventhIssue);

            await Db.SaveChangesAsync();

            //Act
            //TODO: change test - no has new parameters - page and takeCount
            (int count, var resultAllRegions) = (await service.AllAsync <IssuesListingModel>(isApproved, RegionType.All, 1, 5));

            var expectedAllRegions = await this.Db.UrbanIssues.Where(i => i.IsApproved == isApproved).ToListAsync();

            (int countConcreteRegion, var resultConcreteRegion) = (await service.AllAsync <IssuesListingModel>(isApproved, concreteRegion, 1, 5));

            var expectedConcreteRegion = await this.Db.UrbanIssues.Where(i => i.IsApproved == isApproved)
                                         .Where(i => i.Region == concreteRegion).ToListAsync();

            //Assert
            resultAllRegions.Should().AllBeOfType <IssuesListingModel>();
            resultAllRegions.Should().HaveCount(expectedAllRegions.Count);

            resultConcreteRegion.Should().HaveCount(expectedConcreteRegion.Count);
            resultConcreteRegion.Should().HaveCount(expectedConcreteRegion.Count);
        }
Beispiel #6
0
        public async Task DeleteAsyncShould_ReturnsTrue_IfManagerRegionIsEqualToIssueRegion_OrManagerIsForAllRegions()
        {
            //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.Western);
            var secondManager = UserCreator.Create(RegionType.All);
            await Db.AddRangeAsync(manager, secondManager);

            var pic       = ImageInfoCreator.Create();
            var secondPic = ImageInfoCreator.Create();
            await Db.AddRangeAsync(pic, secondPic);

            var issue       = UrbanIssueCreator.CreateIssue(RegionType.Western, pic.Id);
            var secondIssue = UrbanIssueCreator.CreateIssue(RegionType.South, secondPic.Id);

            await Db.AddRangeAsync(issue, secondIssue);

            await Db.SaveChangesAsync();

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

            var result2 = await service.DeleteAsync(secondManager.Id, secondManager.ManagedRegion, secondIssue.Id);

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

            result2.Should().BeTrue();

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

            activityService.Verify(a =>
                                   a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Exactly(2));
        }
        public async Task UpdateAsyncShould_ReturnsFalseIf_UpdaterIsNotTheSameAsUploader()
        {
            //Arrange
            var publisher = UserCreator.Create();
            var updater   = UserCreator.Create();

            await this.Db.AddRangeAsync(publisher, updater);

            var issue = UrbanIssueCreator.CreateIssue(RegionType.All);

            await this.Db.AddAsync(issue);

            var resolved = ResolvedCreator.Create(publisher.Id, issue.Id, DefaultPicId);

            await this.Db.AddAsync(resolved);

            await this.Db.SaveChangesAsync();

            var issueService    = new Mock <IManagerIssueService>();
            var pictureService  = IPictureServiceMock.New(DefaultPicId);
            var activityService = new Mock <IManagerActivityService>();

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

            //Act
            var result = await service.UpdateAsync(updater.Id, resolved.Id, ChangedDescription, null);

            var resolvedAfterAct = await this.Db.FindAsync <ResolvedIssue>(resolved.Id);

            //Assert
            result.Should().Be(false);

            resolved.Should().BeEquivalentTo(resolvedAfterAct);

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

            activityService.Verify(a =>
                                   a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Never);
        }
Beispiel #8
0
        public async Task ApproveAsyncShould_ReturnsFalse_IfManagerRegionIsNotEqualToIssueRegion()
        {
            //Arrange
            var activityService = new Mock <IManagerActivityService>();

            var service = new ManagerIssueService(Db, null, 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.ApproveAsync(manager, issue.Id);

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

            activityService.Verify(a => a.WriteLogAsync(It.IsAny <string>(), It.IsAny <ManagerActivityType>()), Times.Never);
        }
        public async Task DeleteAsyncShould_ReturnsFalse_IfManagerId_IsNotEqualTo_ResolvedPublisherId()
        {
            //Arrange
            var issueService    = new Mock <IManagerIssueService>();
            var pictureService  = IPictureServiceMock.New(DefaultPicId);
            var activityService = new Mock <IManagerActivityService>();

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

            var manager   = UserCreator.Create();
            var publisher = UserCreator.Create();
            await Db.AddRangeAsync(manager, publisher);

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

            var resolved = ResolvedCreator.Create(publisher.Id, issue.Id, 0);
            await Db.AddAsync(resolved);

            await Db.SaveChangesAsync();

            //Act

            var result = await service.DeleteAsync(manager.Id, resolved.Id);

            //Assert

            result.Should().BeFalse();

            issueService.Verify(i => i.RemoveResolvedReferenceAsync(It.IsAny <int>()), Times.Never);

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

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