Exemplo n.º 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 ApiBadgeServerModelMapper();
            ApplicationDbContext        context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IBadgeService               service = testServer.Host.Services.GetService(typeof(IBadgeService)) as IBadgeService;
            ApiBadgeServerResponseModel model   = await service.Get(1);

            ApiBadgeClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

            request.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 1);

            UpdateResponse <ApiBadgeClientResponseModel> updateResponse = await client.BadgeUpdateAsync(model.Id, request);

            context.Entry(context.Set <Badge>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Badge>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Badge>().ToList()[0].Name.Should().Be("B");
            context.Set <Badge>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }
Exemplo n.º 2
0
        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 ApiBadgeClientRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", 1);
            CreateResponse <ApiBadgeClientResponseModel> result = await client.BadgeCreateAsync(model);

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Badge>().ToList()[1].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Badge>().ToList()[1].Name.Should().Be("B");
            context.Set <Badge>().ToList()[1].UserId.Should().Be(1);

            result.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            result.Record.Name.Should().Be("B");
            result.Record.UserId.Should().Be(1);
        }
        public virtual ApiBadgeClientRequestModel MapServerResponseToClientRequest(
            ApiBadgeServerResponseModel response)
        {
            var request = new ApiBadgeClientRequestModel();

            request.SetProperties(
                response.Date,
                response.Name,
                response.UserId);
            return(request);
        }
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiBadgeModelMapper();
            var model  = new ApiBadgeClientRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1);
            ApiBadgeClientResponseModel response = mapper.MapClientRequestToResponse(1, model);

            response.Should().NotBeNull();
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.UserId.Should().Be(1);
        }