Example #1
0
        private async Task <CreateEditAnnualReportViewModel> GetCreateEditViewModel(CityVMs.CityViewModel city, AnnualReportOperation operation, AnnualReportViewModel annualReport)
        {
            var createEditAnnualReportViewModel = await GetCreateEditViewModel(city, operation);

            createEditAnnualReportViewModel.AnnualReport = annualReport;
            return(createEditAnnualReportViewModel);
        }
Example #2
0
        private async Task <CreateEditAnnualReportViewModel> GetCreateEditViewModel(CityVMs.CityViewModel city, AnnualReportOperation operation)
        {
            var cityMemebrsDTO = await _cityMembersService.GetMembersByCityIdAsync(city.ID);

            var cityMembers = _mapper.Map <IEnumerable <CityDTOs.CityMembersDTO>, IEnumerable <CityVMs.CityMembersViewModel> >(cityMemebrsDTO);

            return(new CreateEditAnnualReportViewModel(cityMembers)
            {
                Operation = operation,
                CityName = city.Name,
                AnnualReport = new AnnualReportViewModel
                {
                    CityId = city.ID,
                    MembersStatistic = new MembersStatisticViewModel()
                }
            });
        }
        public async Task CreateAsyncCorrect()
        {
            // Arrange
            IEnumerable <CityDTOs.CityDTO> cities = new List <CityDTOs.CityDTO>
            {
                new CityDTOs.CityDTO {
                    ID = 1, Name = "Львів"
                }
            };
            var city = new CityVMs.CityViewModel {
                ID = cities.First().ID, Name = cities.First().Name
            };
            IEnumerable <CityDTOs.CityMembersDTO> cityMembersDTOs = new List <CityDTOs.CityMembersDTO>
            {
                new CityDTOs.CityMembersDTO {
                    UserId = "1", User = new UserDTOs.CityUserDTO {
                        FirstName = "Петро", LastName = "Петренко"
                    }
                }
            };
            var cityMembers = new List <CityVMs.CityMembersViewModel>
            {
                new CityVMs.CityMembersViewModel
                {
                    UserId = cityMembersDTOs.First().UserId,
                    User   = new CityVMs.CityUserViewModel {
                        FirstName = cityMembersDTOs.First().User.FirstName, LastName = cityMembersDTOs.First().User.LastName
                    }
                }
            };
            var expectedViewModel = new CreateEditAnnualReportViewModel(cityMembers)
            {
                Operation   = AnnualReportOperation.Creating,
                CityName    = city.Name,
                CityMembers = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = ""
                    },
                    new SelectListItem {
                        Value = cityMembers.First().UserId, Text = $"{cityMembers.First().User.FirstName} {cityMembers.First().User.LastName}"
                    }
                },
                CityLegalStatusTypes = new List <SelectListItem>
                {
                    new SelectListItem {
                        Value = "RegisteredLegalEntity", Text = "Зареєстрована юридична особа"
                    },
                    new SelectListItem {
                        Value = "LegalizedByMessage", Text = "Легалізована шляхом повідомлення"
                    },
                    new SelectListItem {
                        Value = "NotLegalizedInByLocalAuthorities", Text = "Нелегалізована у місцевих органах влади"
                    },
                    new SelectListItem {
                        Value = "InTheProcessOfLegalization", Text = "В процесі легалізації/реєстрації"
                    },
                    new SelectListItem {
                        Value = "RegisteredSeparatedSubdivision", Text = "Зареєстрований відокремлений підрозділ"
                    }
                },
                AnnualReport = new AnnualReportViewModel {
                    CityId = city.ID, MembersStatistic = new MembersStatisticViewModel()
                }
            };

            _cityAccessService.Setup(cas => cas.GetCitiesAsync(It.IsAny <ClaimsPrincipal>()))
            .ReturnsAsync(cities);
            _mapper.Setup(m => m.Map <CityDTOs.CityDTO, CityVMs.CityViewModel>(It.IsAny <CityDTOs.CityDTO>()))
            .Returns(city);
            _cityMembersService.Setup(c => c.GetMembersByCityIdAsync(It.IsAny <int>()))
            .ReturnsAsync(cityMembersDTOs);
            _mapper.Setup(m => m.Map <IEnumerable <CityDTOs.CityMembersDTO>, IEnumerable <CityVMs.CityMembersViewModel> >(It.IsAny <IEnumerable <CityDTOs.CityMembersDTO> >()))
            .Returns(cityMembers);

            // Act
            var result = await controller.Create();

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal("CreateEdit", viewResult.ViewName);
            Assert.Null(viewResult.ViewData["ErrorMessage"]);
            var actualViewModel = Assert.IsType <CreateEditAnnualReportViewModel>(viewResult.Model);

            Assert.Equal(JsonConvert.SerializeObject(expectedViewModel), JsonConvert.SerializeObject(actualViewModel));
        }