public void Test_CreateSubscription_IsBeingCreated()
        {
            var id       = Guid.NewGuid();
            var customer = _customerController.Get().First();
            var product  = _productController.Get().First();

            var newSubscription = new Subscription()
            {
                Id = id, CustomerId = customer.Id, ProductId = product.Id
            };

            _subscriptionController.Create(newSubscription);

            var result = _subscriptionController.Get(newSubscription.Id);

            Assert.IsNotNull(result);
            Assert.AreEqual(id, result.Id);
            Assert.AreEqual(customer.Id, result.CustomerId);
            Assert.AreEqual(product.Id, result.ProductId);
        }
コード例 #2
0
        public void WhenAUserSubscribes(string lastName, string firstName, string email)
        {
            var formCollection = new FormCollection
            {
                { "EMail", email },
                { "LastName", lastName },
                { "FirstName", firstName },
            };


            var controller = new SubscriptionController(this.dataStorageMock.Object, this.reportingMock.Object)
            {
                ControllerContext = MvcMockHelpers.GetControllerContextMock("POST")
            };

            var actionResult = controller.Create(formCollection);

            ScenarioContext.Current["Controller"]   = controller;
            ScenarioContext.Current["ActionResult"] = actionResult;
        }
コード例 #3
0
        public async void Create_Errors()
        {
            SubscriptionControllerMockFacade mock = new SubscriptionControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiSubscriptionResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiSubscriptionResponseModel();

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSubscriptionRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSubscriptionResponseModel> >(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 ApiSubscriptionRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSubscriptionRequestModel>()));
        }
コード例 #4
0
        public async void Create_No_Errors()
        {
            SubscriptionControllerMockFacade mock = new SubscriptionControllerMockFacade();

            var mockResponse = new CreateResponse <ApiSubscriptionResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiSubscriptionResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSubscriptionRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSubscriptionResponseModel> >(mockResponse));
            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 ApiSubscriptionRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiSubscriptionResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSubscriptionRequestModel>()));
        }