Ejemplo n.º 1
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 ApiTweetClientRequestModel();

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

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Tweet>().ToList()[1].Content.Should().Be("B");
            context.Set <Tweet>().ToList()[1].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Tweet>().ToList()[1].LocationId.Should().Be(1);
            context.Set <Tweet>().ToList()[1].Time.Should().Be(TimeSpan.Parse("02:00:00"));
            context.Set <Tweet>().ToList()[1].UserUserId.Should().Be(1);

            result.Record.Content.Should().Be("B");
            result.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            result.Record.LocationId.Should().Be(1);
            result.Record.Time.Should().Be(TimeSpan.Parse("02:00:00"));
            result.Record.UserUserId.Should().Be(1);
        }
        public virtual ApiTweetClientRequestModel MapServerResponseToClientRequest(
            ApiTweetServerResponseModel response)
        {
            var request = new ApiTweetClientRequestModel();

            request.SetProperties(
                response.Content,
                response.Date,
                response.LocationId,
                response.Time,
                response.UserUserId);
            return(request);
        }
        public void MapClientRequestToResponse()
        {
            var mapper = new ApiTweetModelMapper();
            var model  = new ApiTweetClientRequestModel();

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

            response.Should().NotBeNull();
            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LocationId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
            response.UserUserId.Should().Be(1);
        }
Ejemplo n.º 4
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 ApiTweetServerModelMapper();
            ApplicationDbContext        context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ITweetService               service = testServer.Host.Services.GetService(typeof(ITweetService)) as ITweetService;
            ApiTweetServerResponseModel model   = await service.Get(1);

            ApiTweetClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiTweetClientResponseModel> updateResponse = await client.TweetUpdateAsync(model.TweetId, request);

            context.Entry(context.Set <Tweet>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.TweetId.Should().Be(1);
            context.Set <Tweet>().ToList()[0].Content.Should().Be("B");
            context.Set <Tweet>().ToList()[0].Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Tweet>().ToList()[0].LocationId.Should().Be(1);
            context.Set <Tweet>().ToList()[0].Time.Should().Be(TimeSpan.Parse("02:00:00"));
            context.Set <Tweet>().ToList()[0].UserUserId.Should().Be(1);

            updateResponse.Record.TweetId.Should().Be(1);
            updateResponse.Record.Content.Should().Be("B");
            updateResponse.Record.Date.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.LocationId.Should().Be(1);
            updateResponse.Record.Time.Should().Be(TimeSpan.Parse("02:00:00"));
            updateResponse.Record.UserUserId.Should().Be(1);
        }