Example #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 ApiCommentClientRequestModel();

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

            result.Success.Should().BeTrue();
            result.Record.Should().NotBeNull();
            context.Set <Comment>().ToList()[1].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Comment>().ToList()[1].PostId.Should().Be(1);
            context.Set <Comment>().ToList()[1].Score.Should().Be(2);
            context.Set <Comment>().ToList()[1].Text.Should().Be("B");
            context.Set <Comment>().ToList()[1].UserId.Should().Be(1);

            result.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            result.Record.PostId.Should().Be(1);
            result.Record.Score.Should().Be(2);
            result.Record.Text.Should().Be("B");
            result.Record.UserId.Should().Be(1);
        }
Example #2
0
        public virtual ApiCommentClientRequestModel MapServerResponseToClientRequest(
            ApiCommentServerResponseModel response)
        {
            var request = new ApiCommentClientRequestModel();

            request.SetProperties(
                response.CreationDate,
                response.PostId,
                response.Score,
                response.Text,
                response.UserId);
            return(request);
        }
Example #3
0
        public void MapClientResponseToRequest()
        {
            var mapper = new ApiCommentModelMapper();
            var model  = new ApiCommentClientResponseModel();

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

            response.Should().NotBeNull();
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostId.Should().Be(1);
            response.Score.Should().Be(1);
            response.Text.Should().Be("A");
            response.UserId.Should().Be(1);
        }
Example #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 ApiCommentServerModelMapper();
            ApplicationDbContext          context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ICommentService               service = testServer.Host.Services.GetService(typeof(ICommentService)) as ICommentService;
            ApiCommentServerResponseModel model   = await service.Get(1);

            ApiCommentClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiCommentClientResponseModel> updateResponse = await client.CommentUpdateAsync(model.Id, request);

            context.Entry(context.Set <Comment>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Comment>().ToList()[0].CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            context.Set <Comment>().ToList()[0].PostId.Should().Be(1);
            context.Set <Comment>().ToList()[0].Score.Should().Be(2);
            context.Set <Comment>().ToList()[0].Text.Should().Be("B");
            context.Set <Comment>().ToList()[0].UserId.Should().Be(1);

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.CreationDate.Should().Be(DateTime.Parse("1/1/1988 12:00:00 AM"));
            updateResponse.Record.PostId.Should().Be(1);
            updateResponse.Record.Score.Should().Be(2);
            updateResponse.Record.Text.Should().Be("B");
            updateResponse.Record.UserId.Should().Be(1);
        }