Пример #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 ApiSubscriptionServerModelMapper();
            ApplicationDbContext context             = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
            ISubscriptionService service             = testServer.Host.Services.GetService(typeof(ISubscriptionService)) as ISubscriptionService;
            ApiSubscriptionServerResponseModel model = await service.Get(1);

            ApiSubscriptionClientRequestModel request = mapper.MapServerResponseToClientRequest(model);

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

            UpdateResponse <ApiSubscriptionClientResponseModel> updateResponse = await client.SubscriptionUpdateAsync(model.Id, request);

            context.Entry(context.Set <Subscription>().ToList()[0]).Reload();
            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
            updateResponse.Record.Id.Should().Be(1);
            context.Set <Subscription>().ToList()[0].Name.Should().Be("B");
            context.Set <Subscription>().ToList()[0].StripePlanName.Should().Be("B");

            updateResponse.Record.Id.Should().Be(1);
            updateResponse.Record.Name.Should().Be("B");
            updateResponse.Record.StripePlanName.Should().Be("B");
        }
Пример #2
0
        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;

            ISubscriptionService service = testServer.Host.Services.GetService(typeof(ISubscriptionService)) as ISubscriptionService;
            var model = new ApiSubscriptionServerRequestModel();

            model.SetProperties("B", "B");
            CreateResponse <ApiSubscriptionServerResponseModel> createdResponse = await service.Create(model);

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

            ActionResponse deleteResult = await client.SubscriptionDeleteAsync(2);

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

            verifyResponse.Should().BeNull();
        }
Пример #3
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiSubscriptionServerModelMapper();
            var model  = new ApiSubscriptionServerResponseModel();

            model.SetProperties(1, "A", "A");
            ApiSubscriptionServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Name.Should().Be("A");
            response.StripePlanName.Should().Be("A");
        }
Пример #4
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiSubscriptionServerResponseModel response = await this.SubscriptionService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Пример #5
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <ISubscriptionService, ISubscriptionRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Subscription>(null));
            var service = new SubscriptionService(mock.LoggerMock.Object,
                                                  mock.MediatorMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Object,
                                                  mock.DALMapperMockFactory.DALSubscriptionMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #6
0
        public async void Create_Errors()
        {
            SubscriptionControllerMockFacade mock = new SubscriptionControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSubscriptionServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSubscriptionServerResponseModel> >(mockResponse.Object));
            SubscriptionController controller = new SubscriptionController(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 ApiSubscriptionServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSubscriptionServerRequestModel>()));
        }
Пример #7
0
        public async void All_Exists()
        {
            SubscriptionControllerMockFacade mock = new SubscriptionControllerMockFacade();
            var record  = new ApiSubscriptionServerResponseModel();
            var records = new List <ApiSubscriptionServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            SubscriptionController controller = new SubscriptionController(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 <ApiSubscriptionServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Пример #8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSubscriptionServerRequestModel> patch)
        {
            ApiSubscriptionServerResponseModel record = await this.SubscriptionService.Get(id);

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

                UpdateResponse <ApiSubscriptionServerResponseModel> result = await this.SubscriptionService.Update(id, model);

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