Ejemplo n.º 1
0
        public async Task CreateIssue_WhenAddFailed_ReturnProjectCreationFailedResponse()
        {
            var     projectPassed = ProjectsDbSet.ProjectBuilder().Create <ProjectDto>();
            Project modelAfterMap = new Project();

            MockFor <IBaseMapper <Project, ProjectDto> >().Setup(e => e.MapToEntity(It.IsAny <ProjectDto>()))
            .Returns(modelAfterMap);
            MockFor <IProjectRepository>().Setup(x => x.AddAsync(modelAfterMap))
            .ReturnsAsync((Project)null);

            var result = await ClassUnderTest.CreateProjectAsync(projectPassed);

            result.VerifyNotSuccessResponseWithErrorCodeAndMessage(ErrorCode.ProjectCreationFailed);
        }
        public async Task ProjectRepository_AddAsync_AddsValueToDatabase()
        {
            var expectedCount = ProjectsDbSet.Get().ToList().Count + 1;
            var entityToAdd   = ProjectsDbSet.ProjectBuilder().Create();

            await using var context = new TimeTrackingDbContext(_dbOptions);
            var projectRepository = new ProjectRepository(context);

            await projectRepository.AddAsync(entityToAdd);

            context.Projects.Should().HaveCount(expectedCount);
            var entityFound = await context.Projects.FindAsync(entityToAdd.Id);

            entityFound.Should().BeEquivalentTo(entityToAdd);
            // Assert.That(entityFound, Is.EqualTo(entityToAdd).Using(EqualityComparers.ProjectComparer));
        }
Ejemplo n.º 3
0
        public async Task CreateIssue_WhenExceptionThrows_ReturnInternalError()
        {
            var     projectPassed = ProjectsDbSet.ProjectBuilder().Create <ProjectDto>();
            Project modelAfterMap = new Project();

            MockFor <IBaseMapper <Project, ProjectDto> >().Setup(e => e.MapToEntity(It.IsAny <ProjectDto>()))
            .Returns(modelAfterMap);
            MockFor <IBaseMapper <Project, ProjectDto> >().Setup(e => e.MapToModel(It.IsAny <Project>()))
            .Returns(projectPassed);
            MockFor <IProjectRepository>().Setup(x => x.AddAsync(modelAfterMap))
            .ThrowsAsync(new Exception());

            var result = await ClassUnderTest.CreateProjectAsync(projectPassed);

            result.VerifyInternalError();
        }
Ejemplo n.º 4
0
        public async Task CreateIssue_WhenAddSuccess_ReturnProjectMappedResponse()
        {
            var     projectPassed = ProjectsDbSet.ProjectBuilder().Create <ProjectDto>();
            Project modelAfterMap = new Project();

            MockFor <IBaseMapper <Project, ProjectDto> >().Setup(e => e.MapToEntity(It.IsAny <ProjectDto>()))
            .Returns(modelAfterMap);
            MockFor <IBaseMapper <Project, ProjectDto> >().Setup(e => e.MapToModel(It.IsAny <Project>()))
            .Returns(projectPassed);
            MockFor <IProjectRepository>().Setup(x => x.AddAsync(modelAfterMap))
            .ReturnsAsync(new Project());

            var result = await ClassUnderTest.CreateProjectAsync(projectPassed);

            result.VerifySuccessResponseWithData(projectPassed);
        }
Ejemplo n.º 5
0
        public async Task GetAllProjectPagedAsync_WhenRequestedWithPage_ReturnsAllProjectsPaged()
        {
            var pagedRequest = new PagedRequest()
            {
                Page     = 1,
                PageSize = 2
            };
            var calls              = 0;
            var pagedItems         = ProjectsDbSet.ProjectBuilder().CreateMany <Project>();
            var pagedItemsAfterMap = Fixture.CreateMany <ProjectDetailsDto>().ToList();
            var pagedProjects      = PagedResult <Project> .Paginate(pagedItems, 1, 2, 4, 8);

            MockFor <IProjectRepository>().Setup(e => e.GetAllPagedAsync(pagedRequest.Page, pagedRequest.PageSize))
            .ReturnsAsync(pagedProjects);
            MockFor <IModelMapper <Project, ProjectDetailsDto> >().Setup(e => e.MapToModel(It.IsAny <Project>()))
            .Returns(() => pagedItemsAfterMap[calls])
            .Callback(() => calls++);

            var response = await ClassUnderTest.GetAllProjectPagedAsync(pagedRequest);

            response.VerifyCorrectPagination(pagedProjects, pagedItemsAfterMap);
        }