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;

            IQuoteTweetService service = testServer.Host.Services.GetService(typeof(IQuoteTweetService)) as IQuoteTweetService;
            var model = new ApiQuoteTweetServerRequestModel();

            model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), 1, 1, TimeSpan.Parse("02:00:00"));
            CreateResponse <ApiQuoteTweetServerResponseModel> createdResponse = await service.Create(model);

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

            ActionResponse deleteResult = await client.QuoteTweetDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Ejemplo n.º 2
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiQuoteTweetServerResponseModel response = await this.QuoteTweetService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 3
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiQuoteTweetServerModelMapper();
            var model  = new ApiQuoteTweetServerResponseModel();

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

            response.Should().NotBeNull();
            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.RetweeterUserId.Should().Be(1);
            response.SourceTweetId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
        }
Ejemplo n.º 4
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IQuoteTweetService, IQuoteTweetRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <QuoteTweet>(null));
            var service = new QuoteTweetService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.QuoteTweetModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALQuoteTweetMapperMock);

            ApiQuoteTweetServerResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 5
0
        public async void Create_Errors()
        {
            QuoteTweetControllerMockFacade mock = new QuoteTweetControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiQuoteTweetServerResponseModel> >(null as ApiQuoteTweetServerResponseModel);
            var mockRecord   = new ApiQuoteTweetServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiQuoteTweetServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiQuoteTweetServerResponseModel> >(mockResponse.Object));
            QuoteTweetController controller = new QuoteTweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiQuoteTweetServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiQuoteTweetServerRequestModel>()));
        }
Ejemplo n.º 6
0
        public async void All_Exists()
        {
            QuoteTweetControllerMockFacade mock = new QuoteTweetControllerMockFacade();
            var record  = new ApiQuoteTweetServerResponseModel();
            var records = new List <ApiQuoteTweetServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            QuoteTweetController controller = new QuoteTweetController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiQuoteTweetServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
        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 ApiQuoteTweetServerModelMapper();
            ApplicationDbContext             context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            IQuoteTweetService               service = testServer.Host.Services.GetService(typeof(IQuoteTweetService)) as IQuoteTweetService;
            ApiQuoteTweetServerResponseModel model   = await service.Get(1);

            ApiQuoteTweetClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiQuoteTweetClientResponseModel> updateResponse = await client.QuoteTweetUpdateAsync(model.QuoteTweetId, request);

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

            updateResponse.Record.QuoteTweetId.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.RetweeterUserId.Should().Be(1);
            updateResponse.Record.SourceTweetId.Should().Be(1);
            updateResponse.Record.Time.Should().Be(TimeSpan.Parse("02:00:00"));
        }
Ejemplo n.º 8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiQuoteTweetServerRequestModel> patch)
        {
            ApiQuoteTweetServerResponseModel record = await this.QuoteTweetService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiQuoteTweetServerRequestModel model = await this.PatchModel(id, patch) as ApiQuoteTweetServerRequestModel;

                UpdateResponse <ApiQuoteTweetServerResponseModel> result = await this.QuoteTweetService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }