Esempio n. 1
0
        [InlineData(4)] //Client with id 4 has related LegalCases
        public async void GetClientByIdWithLegalCasesAsync_Returns_One_Client_With_Related_LegalCases(int id)
        {
            //get the Client with id 4 (that has related LegalCases) and map it to its DTO
            var client = _clients.First <Client>(cl => cl.Id == id);

            client.LegalCases = LegalCasesData.getTestLegalCases() as ICollection <LegalCase>;
            var expectedClientDto = _mapper.Map <ClientWithLegalCasesDTO>(client);

            //specify the mockRepo return
            _mockRepository.Setup(repo => repo.GetOneByWithRelatedDataAsync(cl => cl.Id == id, cl => cl.LegalCases)).ReturnsAsync(client);

            //instantiate the controller, and call the method
            var controller = new ClientsController(_mockRepository.Object, _mapper, _logger);

            //Call the SUT method
            var actionResult = await controller.GetClientByIdWithLegalCasesAsync(id);

            //Assert the result
            Assert.NotNull(actionResult);

            //convert ActionResult to OkObjectResult to get its Value: a Client type
            var result = Assert.IsType <OkObjectResult>(actionResult.Result);
            //get the ObjectResult.Value
            var actualClientDto = result.Value as ClientWithLegalCasesDTO;

            //use FluentAssertions to compare Reference types
            actualClientDto.Should().BeEquivalentTo(expectedClientDto, options => options.ComparingByMembers <ClientWithLegalCasesDTO>());
        }
Esempio n. 2
0
        public static void SeedDB(CMTestsDbContext context)
        {
            context.AddRange(AddressesData.getTestAddresses());
            context.AddRange(BillableActivitiesData.getTestBillableActivities());
            context.AddRange(ClientsData.getTestClients());
            context.AddRange(ContactsData.getTestContacts());
            context.AddRange(EmployeesData.getTestEmployees());
            context.AddRange(EmployeeTypesData.getTestEmployeeTypes());
            context.AddRange(LegalCasesData.getTestLegalCases());

            context.SaveChanges();
        }
Esempio n. 3
0
        public LegalCaseControllerTests()
        {
            //AutoMapper Configuration
            var profiles      = new AutoMapperProfiles();
            var configuration = new MapperConfiguration(config => config.AddProfile(profiles));

            _mapper = new Mapper(configuration);

            //Configure Logger Mock
            var _loggerMock = new Mock <ILogger <LegalCasesController> >();

            _logger = _loggerMock.Object;

            //Repo and Controller initialization
            _mockRepository = new Mock <IGenericRepository <LegalCase> >();
            _controller     = new LegalCasesController(_mockRepository.Object, _mapper, _logger);

            //Create Custom ControllerContext and add it to Controller for logging in the Controller in case of error
            _controller.ControllerContext = new ControllerContextModel();

            //Load LegalCases Test Data
            _legalCases = LegalCasesData.getTestLegalCases();
        }