Пример #1
0
        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 ApiEventStatusServerModelMapper();
            ApplicationDbContext context            = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IEventStatusService  service            = testServer.Host.Services.GetService(typeof(IEventStatusService)) as IEventStatusService;
            ApiEventStatusServerResponseModel model = await service.Get(1);

            ApiEventStatusClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B");

            UpdateResponse <ApiEventStatusClientResponseModel> updateResponse = await client.EventStatusUpdateAsync(model.Id, request);

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

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
        }
Пример #2
0
        public ActionResult <ItemResponse <EventStatus> > Get()
        {
            int          code     = 200;
            BaseResponse response = null;

            try
            {
                List <EventStatus> eventStatus = _service.Get();

                if (eventStatus == null)
                {
                    code     = 404;
                    response = new ErrorResponse("App resource not found.");
                }
                else
                {
                    response = new ItemResponse <List <EventStatus> > {
                        Item = eventStatus
                    };
                }
            }
            catch (Exception ex)
            {
                code = 500;
                Logger.LogError(ex.ToString());
                response = new ErrorResponse(ex.Message);
            }

            return(StatusCode(code, response));
        }
Пример #3
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;

            IEventStatusService service = testServer.Host.Services.GetService(typeof(IEventStatusService)) as IEventStatusService;
            var model = new ApiEventStatusServerRequestModel();

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

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

            ActionResponse deleteResult = await client.EventStatusDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }