Exemplo n.º 1
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IPersonService service = testServer.Host.Services.GetService(typeof(IPersonService)) as IPersonService;
            var            model   = new ApiPersonServerRequestModel();

            model.SetProperties("B");
            CreateResponse <ApiPersonServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.PersonDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiPersonServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
Exemplo n.º 2
0
        public void MapServerRequestToResponse()
        {
            var mapper = new ApiPersonServerModelMapper();
            var model  = new ApiPersonServerRequestModel();

            model.SetProperties("A");
            ApiPersonServerResponseModel response = mapper.MapServerRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.PersonName.Should().Be("A");
        }
Exemplo n.º 3
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IPersonService, IPersonRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Person>(null));
            var service = new PersonService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.PersonModelValidatorMock.Object,
                                            mock.DALMapperMockFactory.DALPersonMapperMock,
                                            mock.DALMapperMockFactory.DALColumnSameAsFKTableMapperMock);

            ApiPersonServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 4
0
        public async void Get_ShouldReturnRecords()
        {
            var mock   = new ServiceMockFacade <IPersonService, IPersonRepository>();
            var record = new Person();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new PersonService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.PersonModelValidatorMock.Object,
                                            mock.DALMapperMockFactory.DALPersonMapperMock,
                                            mock.DALMapperMockFactory.DALCallPersonMapperMock);

            ApiPersonServerResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }