public virtual async void TestCreate()
        {
            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;

            var model = new ApiOfficerClientRequestModel();

            model.SetProperties("B", "B", "B", "B", "B");
            CreateResponse <ApiOfficerClientResponseModel> result = await client.OfficerCreateAsync(model);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Officer>().ToList()[1].Badge.Should().Be("B");
            context.Set <Officer>().ToList()[1].Email.Should().Be("B");
            context.Set <Officer>().ToList()[1].FirstName.Should().Be("B");
            context.Set <Officer>().ToList()[1].LastName.Should().Be("B");
            context.Set <Officer>().ToList()[1].Password.Should().Be("B");

            result.Record.Badge.Should().Be("B");
            result.Record.Email.Should().Be("B");
            result.Record.FirstName.Should().Be("B");
            result.Record.LastName.Should().Be("B");
            result.Record.Password.Should().Be("B");
        }
Beispiel #2
0
        public virtual ApiOfficerClientRequestModel MapServerResponseToClientRequest(
            ApiOfficerServerResponseModel response)
        {
            var request = new ApiOfficerClientRequestModel();

            request.SetProperties(
                response.Badge,
                response.Email,
                response.FirstName,
                response.LastName,
                response.Password);
            return(request);
        }
Beispiel #3
0
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiOfficerModelMapper();
            var model  = new ApiOfficerClientRequestModel();

            model.SetProperties("A", "A", "A", "A", "A");
            ApiOfficerClientResponseModel response = mapper.MapClientRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.Badge.Should().Be("A");
            response.Email.Should().Be("A");
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.Password.Should().Be("A");
        }
        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 ApiOfficerServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IOfficerService               service = testServer.Host.Services.GetService(typeof(IOfficerService)) as IOfficerService;
            ApiOfficerServerResponseModel model   = await service.Get(1);

            ApiOfficerClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties("B", "B", "B", "B", "B");

            UpdateResponse <ApiOfficerClientResponseModel> updateResponse = await client.OfficerUpdateAsync(model.Id, request);

            context.Entry(context.Set <Officer>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Officer>().ToList()[0].Badge.Should().Be("B");
            context.Set <Officer>().ToList()[0].Email.Should().Be("B");
            context.Set <Officer>().ToList()[0].FirstName.Should().Be("B");
            context.Set <Officer>().ToList()[0].LastName.Should().Be("B");
            context.Set <Officer>().ToList()[0].Password.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Badge.Should().Be("B");
            updateResponse.Record.Email.Should().Be("B");
            updateResponse.Record.FirstName.Should().Be("B");
            updateResponse.Record.LastName.Should().Be("B");
            updateResponse.Record.Password.Should().Be("B");
        }