Esempio n. 1
0
        public async void Update_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <ITeamService, ITeamRepository>();
            var model = new ApiTeamServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Team>())).Returns(Task.FromResult(new Team()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Team()));
            var service = new TeamService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.TeamModelValidatorMock.Object,
                                          mock.DALMapperMockFactory.DALTeamMapperMock,
                                          mock.DALMapperMockFactory.DALChainMapperMock);

            UpdateResponse <ApiTeamServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.TeamModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiTeamServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Team>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeamUpdatedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 2
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <IMachineService, IMachineRepository>();

            var model = new ApiMachineServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Machine>())).Returns(Task.FromResult(new Machine()));
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALMachineMapperMock,
                                             mock.DALMapperMockFactory.DALLinkMapperMock);

            CreateResponse <ApiMachineServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.MachineModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMachineServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Machine>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <MachineCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
Esempio n. 3
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IMachineRepository>();
            var model = new ApiMachineRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Machine>())).Returns(Task.FromResult(new Machine()));
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLMachineMapperMock,
                                             mock.DALMapperMockFactory.DALMachineMapperMock,
                                             mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                             mock.DALMapperMockFactory.DALLinkMapperMock,
                                             mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock,
                                             mock.DALMapperMockFactory.DALMachineRefTeamMapperMock);

            CreateResponse <ApiMachineResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.MachineModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMachineRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Machine>()));
        }
Esempio n. 4
0
        public async void All()
        {
            var mock    = new ServiceMockFacade <IMachineRepository>();
            var records = new List <Machine>();

            records.Add(new Machine());
            mock.RepositoryMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLMachineMapperMock,
                                             mock.DALMapperMockFactory.DALMachineMapperMock,
                                             mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                             mock.DALMapperMockFactory.DALLinkMapperMock,
                                             mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock,
                                             mock.DALMapperMockFactory.DALMachineRefTeamMapperMock);

            List <ApiMachineResponseModel> response = await service.All();

            response.Should().HaveCount(1);
            mock.RepositoryMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Esempio n. 5
0
        public async void Links_Exists()
        {
            var mock    = new ServiceMockFacade <IMachineRepository>();
            var records = new List <Link>();

            records.Add(new Link());
            mock.RepositoryMock.Setup(x => x.Links(default(int), It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLMachineMapperMock,
                                             mock.DALMapperMockFactory.DALMachineMapperMock,
                                             mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                             mock.DALMapperMockFactory.DALLinkMapperMock,
                                             mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock,
                                             mock.DALMapperMockFactory.DALMachineRefTeamMapperMock);

            List <ApiLinkResponseModel> response = await service.Links(default(int));

            response.Should().NotBeEmpty();
            mock.RepositoryMock.Verify(x => x.Links(default(int), It.IsAny <int>(), It.IsAny <int>()));
        }
Esempio n. 6
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IMachineRepository>();
            var model = new ApiMachineRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new MachineService(mock.LoggerMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object,
                                             mock.BOLMapperMockFactory.BOLMachineMapperMock,
                                             mock.DALMapperMockFactory.DALMachineMapperMock,
                                             mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                             mock.DALMapperMockFactory.DALLinkMapperMock,
                                             mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock,
                                             mock.DALMapperMockFactory.DALMachineRefTeamMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.MachineModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Esempio n. 7
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <IChainRepository>();
            var model = new ApiChainRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Chain>())).Returns(Task.FromResult(new Chain()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Chain()));
            var service = new ChainService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ChainModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLChainMapperMock,
                                           mock.DALMapperMockFactory.DALChainMapperMock,
                                           mock.BOLMapperMockFactory.BOLClaspMapperMock,
                                           mock.DALMapperMockFactory.DALClaspMapperMock,
                                           mock.BOLMapperMockFactory.BOLLinkMapperMock,
                                           mock.DALMapperMockFactory.DALLinkMapperMock);

            UpdateResponse <ApiChainResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.ChainModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiChainRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Chain>()));
        }
Esempio n. 8
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ILinkLogService, ILinkLogRepository>();
            var model         = new ApiLinkLogServerRequestModel();
            var validatorMock = new Mock <IApiLinkLogServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new LinkLogService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             validatorMock.Object,
                                             mock.DALMapperMockFactory.DALLinkLogMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <LinkLogDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 9
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IOrganizationService, IOrganizationRepository>();
            var model         = new ApiOrganizationServerRequestModel();
            var validatorMock = new Mock <IApiOrganizationServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiOrganizationServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new OrganizationService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  validatorMock.Object,
                                                  mock.DALMapperMockFactory.DALOrganizationMapperMock,
                                                  mock.DALMapperMockFactory.DALTeamMapperMock);

            CreateResponse <ApiOrganizationServerResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiOrganizationServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <OrganizationCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 10
0
        public async void Update_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IClaspService, IClaspRepository>();
            var model         = new ApiClaspServerRequestModel();
            var validatorMock = new Mock <IApiClaspServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiClaspServerRequestModel>())).Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Clasp()));
            var service = new ClaspService(mock.LoggerMock.Object,
                                           mock.MediatorMock.Object,
                                           mock.RepositoryMock.Object,
                                           validatorMock.Object,
                                           mock.DALMapperMockFactory.DALClaspMapperMock);

            UpdateResponse <ApiClaspServerResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiClaspServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ClaspUpdatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }