Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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));
        }
Пример #7
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);
        }