예제 #1
0
        private static ShoppingCartController GetShoppingCartController(IConfiguration config)
        {
            var controller = new ShoppingCartController(new DatabaseContext(config));

            HttpContextStub.SetupController(controller);
            return(controller);
        }
예제 #2
0
        private static AccountController GetAcountController(RouteData routedata)
        {
            var controller = new AccountController();

            HttpContextStub.SetupController(controller, routedata);
            return(controller);
        }
        private ShoppingCartController GetShoppingCartController()
        {
            var controller = new ShoppingCartController();

            HttpContextStub.SetupController(controller);
            return(controller);
        }
예제 #4
0
        private static AgencyPropertyController GetAgencyPropertyController()
        {
            var controller = new AgencyPropertyController();

            HttpContextStub.SetupController(controller);
            return(controller);
        }
예제 #5
0
        private static ProjectController GetProjectController()
        {
            var controller = new ProjectController();

            HttpContextStub.SetupController(controller);
            return(controller);
        }
        private ShoppingCartController GetShoppingCartController()
        {
            var controller = new ShoppingCartController(_databaseContext, new ShoppingCartLogic(_databaseContext));

            HttpContextStub.SetupController(controller);
            return(controller);
        }
예제 #7
0
        public void Deserialize_WhenEmptyInput_JustInstantiateModel()
        {
            var ctx = new HttpContextStub();

            var serializer = new FormBasedSerializer<Customer>() as IModelSerializer<Customer>;
            var model = serializer.Deserialize("customer", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.IsNotNull(model);
        }
        public void CreateFormTagHelper()
        {
            _viewBag = new Dictionary<string, object>();
            var viewReq = new ViewRequest();
            _httpCtx = new HttpContextStub();
            _ctx = new ViewContext(_httpCtx, _viewBag, new object(), viewReq);

            _formTagHlpr = new FormTagHelper(_ctx);
            _url = new StubTargetUrl();
        }
예제 #9
0
        public void Deserialize_WithDepth0EnumInput_FillsProperty()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["company[category]"] = "Industry";

            var serializer = new FormBasedSerializer<Company>() as IModelSerializer<Company>;
            var model = serializer.Deserialize("company", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.AreEqual(CompanyCategory.Industry, model.Category);
        }
예제 #10
0
        public void Deserialize_WithDepth0DecimalInput_FillsProperty()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["company[revenue]"] = "17.3";

            var serializer = new FormBasedSerializer<Company>() as IModelSerializer<Company>;
            var model = serializer.Deserialize("company", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.AreEqual(17.3m, model.Revenue);
        }
예제 #11
0
        public void Deserialize_WithDepth0DatetimeInput_FillsProperty()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["company[since]"] = "01/01/1950";

            var serializer = new FormBasedSerializer<Company>() as IModelSerializer<Company>;
            var model = serializer.Deserialize("company", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.AreEqual(new DateTime(1950, 1, 1), model.Since);
        }
예제 #12
0
        public void InitializeDoesNotThrowIfHeaderCollectionIsUnavailable()
        {
            var httpContext = new HttpContextStub();

            httpContext.OnRequestGetter = () => new HttpRequestStub(httpContext);

            var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessorWithoutRequest(httpContext, new RequestTelemetry());

            var initializer = new ClientIpHeaderTelemetryInitializer(contextAccessor);

            initializer.Initialize(new EventTelemetry());
        }
예제 #13
0
        public void Customize(IFixture fixture)
        {
            var routes = new RouteCollection();

            var httpContext = new HttpContextStub();

            fixture.Customize <TController>(c => c
                                            .With(controller => controller.ControllerContext, new ControllerContext()
            {
                HttpContext = httpContext
            })
                                            .With(controller => controller.Url, new UrlHelper(new RequestContext(httpContext, new RouteData()), routes))
                                            .OmitAutoProperties());
        }
        public void InitializeFallsbackToEnvIfHeaderCollectionIsUnavailable()
        {
            try
            {
                Environment.SetEnvironmentVariable("WEBSITE_HOSTNAME", "RoleNameEnv");
                var httpContext = new HttpContextStub();
                httpContext.OnRequestGetter = () => new HttpRequestStub(httpContext);

                var contextAccessor = HttpContextAccessorHelper.CreateHttpContextAccessorWithoutRequest(httpContext, new RequestTelemetry());

                var initializer = new AzureAppServiceRoleNameFromHostNameHeaderInitializer(contextAccessor);
                var req         = new RequestTelemetry();
                initializer.Initialize(req);

                Assert.Equal("RoleNameEnv", req.Context.Cloud.RoleName);
            }
            finally
            {
                Environment.SetEnvironmentVariable("WEBSITE_HOSTNAME", null);
            }
        }
예제 #15
0
        public void Deserialize_WithDepth1IntForCollection_CreatesAndFillsCollection()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["customer[permissions][id]"] = "10";

            var serializer = new FormBasedSerializer<Customer>() as IModelSerializer<Customer>;
            var model = serializer.Deserialize("customer", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.IsNotNull(model.Permissions);
            Assert.AreEqual(1, model.Permissions.Count);
            Assert.AreEqual(10, model.Permissions[0].Id);
        }
예제 #16
0
        public void Deserialize_WithMultipleEntriesWithMultiplesFieldsForSameCollection_CreatesAndFillsCollection()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["customer[permissions][id]"] = "10,11,12,13";
            form["customer[permissions][name]"] = "n1,n2,n3,n4";

            var serializer = new FormBasedSerializer<Customer>() as IModelSerializer<Customer>;
            var model = serializer.Deserialize("customer", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.IsNotNull(model.Permissions);
            Assert.AreEqual(4, model.Permissions.Count);

            Assert.AreEqual(10, model.Permissions[0].Id);
            Assert.AreEqual("n1", model.Permissions[0].Name);

            Assert.AreEqual(11, model.Permissions[1].Id);
            Assert.AreEqual("n2", model.Permissions[1].Name);

            Assert.AreEqual(12, model.Permissions[2].Id);
            Assert.AreEqual("n3", model.Permissions[2].Name);

            Assert.AreEqual(13, model.Permissions[3].Id);
            Assert.AreEqual("n4", model.Permissions[3].Name);
        }
 public Account_UserRegistration_Steps()
 {
     _accountController = new AccountController();
     HttpContextStub.SetupController(_accountController);
 }
예제 #18
0
        public void Deserialize_WithDepth0GuidInput_FillsProperty()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["company[id]"] = "6C8A7A2C-0E37-45D5-B1AF-56A714AB47D5";

            var serializer = new FormBasedSerializer<Company>() as IModelSerializer<Company>;
            var model = serializer.Deserialize("company", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.AreEqual(Guid.Parse("6C8A7A2C-0E37-45D5-B1AF-56A714AB47D5"), model.Id);
        }
예제 #19
0
        public void Deserialize_WithDepth0StringInput_FillsProperty()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["customer[name]"] = "hammett";

            var serializer = new FormBasedSerializer<Customer>() as IModelSerializer<Customer>;
            var model = serializer.Deserialize("customer", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.AreEqual("hammett", model.Name);
        }
예제 #20
0
        public void Deserialize_WithDepth1StringInput_FillsProperty()
        {
            var ctx = new HttpContextStub();
            var form = ctx.RequestStub.Form;
            form["customer[address][city]"] = "kirkland";

            var serializer = new FormBasedSerializer<Customer>() as IModelSerializer<Customer>;
            var model = serializer.Deserialize("customer", "", ctx.Request, new DataAnnotationsModelMetadataProvider());

            Assert.IsNotNull(model.Address);
            Assert.AreEqual("kirkland", model.Address.City);
        }