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;

            IChainStatusService service = testServer.Host.Services.GetService(typeof(IChainStatusService)) as IChainStatusService;
            var model = new ApiChainStatusServerRequestModel();

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

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

            ActionResponse deleteResult = await client.ChainStatusDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
        public virtual async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            var mapper = new ApiChainStatusServerModelMapper();
            ApplicationDbContext context            = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IChainStatusService  service            = testServer.Host.Services.GetService(typeof(IChainStatusService)) as IChainStatusService;
            ApiChainStatusServerResponseModel model = await service.Get(1);

            ApiChainStatusClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiChainStatusClientResponseModel> updateResponse = await client.ChainStatusUpdateAsync(model.Id, request);

            context.Entry(context.Set <ChainStatus>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <ChainStatus>().ToList()[0].Name.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiChainStatusServerModelMapper();
            var model  = new ApiChainStatusServerResponseModel();

            model.SetProperties(1, "A");
            ApiChainStatusServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Name.Should().Be("A");
        }
Example #4
0
        public async virtual Task <IActionResult> ByName(string name)
        {
            ApiChainStatusServerResponseModel response = await this.ChainStatusService.ByName(name);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Example #5
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiChainStatusServerResponseModel response = await this.ChainStatusService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Example #6
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IChainStatusService, IChainStatusRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ChainStatus>(null));
            var service = new ChainStatusService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.ChainStatusModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALChainStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALChainMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Example #7
0
        public async void ByName_Not_Exists()
        {
            var mock = new ServiceMockFacade <IChainStatusService, IChainStatusRepository>();

            mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult <ChainStatus>(null));
            var service = new ChainStatusService(mock.LoggerMock.Object,
                                                 mock.MediatorMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.ChainStatusModelValidatorMock.Object,
                                                 mock.DALMapperMockFactory.DALChainStatusMapperMock,
                                                 mock.DALMapperMockFactory.DALChainMapperMock);

            ApiChainStatusServerResponseModel response = await service.ByName("test_value");

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>()));
        }
        public async void Create_Errors()
        {
            ChainStatusControllerMockFacade mock = new ChainStatusControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiChainStatusServerResponseModel> >(null as ApiChainStatusServerResponseModel);
            var mockRecord   = new ApiChainStatusServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiChainStatusServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiChainStatusServerResponseModel> >(mockResponse.Object));
            ChainStatusController controller = new ChainStatusController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiChainStatusServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiChainStatusServerRequestModel>()));
        }
        public async void All_Exists()
        {
            ChainStatusControllerMockFacade mock = new ChainStatusControllerMockFacade();
            var record  = new ApiChainStatusServerResponseModel();
            var records = new List <ApiChainStatusServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            ChainStatusController controller = new ChainStatusController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiChainStatusServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Example #10
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiChainStatusServerRequestModel> patch)
        {
            ApiChainStatusServerResponseModel record = await this.ChainStatusService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiChainStatusServerRequestModel model = await this.PatchModel(id, patch) as ApiChainStatusServerRequestModel;

                UpdateResponse <ApiChainStatusServerResponseModel> result = await this.ChainStatusService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }