예제 #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 ParticipateShould_ReturnsTrueIf_UserIsNotParticipatingEvent()
        {
            //Arrange
            var user = UserCreator.Create();

            await this.Db.AddAsync(user);

            var image = ImageInfoCreator.Create();

            await this.Db.AddAsync(image);

            var firstEvent = EventCreator.Create(user.Id, null);

            await this.Db.AddAsync(firstEvent);

            await this.Db.SaveChangesAsync();

            var service = new EventService(Db, null);

            //Act
            var result = await service.Participate(firstEvent.Id, user.Id);

            //Assert

            result.Should().BeTrue();

            this.Db.EventUsers.Should().Contain(eu => eu.EventId == firstEvent.Id && eu.ParticipantId == user.Id);
        }
예제 #3
0
        public async Task ParticipateShould_ReturnFalseIf_UserIsAlreadyParticipatingEvent()
        {
            //Arrange
            var user = UserCreator.Create();

            await this.Db.AddAsync(user);

            var image = ImageInfoCreator.Create();

            await this.Db.AddAsync(image);

            var firstEvent = EventCreator.Create(user.Id, null);

            await this.Db.AddAsync(firstEvent);

            var eventUser = EventCreator.CreateEventUser(firstEvent.Id, user.Id);

            await this.Db.AddAsync(eventUser);

            await this.Db.SaveChangesAsync();

            var service = new EventService(Db, null);

            //Act
            var result = await service.Participate(firstEvent.Id, user.Id);

            //Assert

            result.Should().Be(false);
        }
예제 #4
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);
        }
예제 #5
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));
        }