public IEnumerable <DTOProducts> GetProdutsForCatalog(int productType_id, HeatingFloorFilter filter)
        {
            string productOptSql = EmbeddedResourceManager.GetString(typeof(ProductsService), DTOPath.DTOProductOptionsSql) + " where p.productType_id = @productType_id";

            IEnumerable <DTOProductOptions> productsOptions = database.ExucuteQuery <DTOProductOptions>(productOptSql, new { productType_id });

            if (productsOptions != null)
            {
                productsOptions = filterService.ApplyHeatingFloorFilter(filter, productsOptions);

                IEnumerable <string> product_ids = productsOptions.Select(x => x.product_id.ToString()).Distinct();

                string productSql = EmbeddedResourceManager.GetString(typeof(ProductsService), DTOPath.DTOProductSql) + " where p.product_id in @product_ids";

                IEnumerable <DTOProducts> products = database.ExucuteQuery <DTOProducts>(productSql, new { product_ids });

                products = filterService.ApplyManyfacturersFilter(filter.manufacturer.Select(x => x.manufacturer_id).ToArray(), products);

                return(products);
            }
            else
            {
                throw new ArgumentNullException(nameof(productsOptions));
            }
        }
Exemple #2
0
        public void V1BitcoinT01DeserializeRequest()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_btc_01_req.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            jsonRpcSerializer.RequestContracts["getblockhash"] = new JsonRpcRequestContract(new[] { typeof(long) });

            var jsonRpcData = jsonRpcSerializer.DeserializeRequestData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.Equal("foo", jsonRpcMessage.Id);
            Assert.Equal("getblockhash", jsonRpcMessage.Method);
            Assert.Equal(JsonRpcParametersType.ByPosition, jsonRpcMessage.ParametersType);
            Assert.Equal(new object[] { 0L }, jsonRpcMessage.ParametersByPosition);
        }
Exemple #3
0
        public void V2CoreDeserializeResponseDataWhenHasDataIsFalse()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_core_error_has_data_false.json");
            var jsonRpcSerializer = new JsonRpcSerializer();

            jsonRpcSerializer.ResponseContracts["m"]     = new JsonRpcResponseContract(typeof(string));
            jsonRpcSerializer.StaticResponseBindings[1L] = "m";

            var jsonRpcData = jsonRpcSerializer.DeserializeResponseData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.False(jsonRpcMessage.Success);

            var jsonRpcError = jsonRpcMessage.Error;

            Assert.False(jsonRpcError.HasData);
            Assert.Null(jsonRpcError.Data);
        }
        public void CoreDeserializeRequestDatatFromStream()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v2_core_req.json");
            //var jsonSample = EmbeddedResourceManager.GetString("Assets.v2_spec_01.1_req.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer();

            jsonRpcSerializer.RequestContracts["m"] = new JsonRpcRequestContract();

            using (var jsonStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonSample)))
            {
                var jsonRpcData = jsonRpcSerializer.DeserializeRequestData(jsonStream);

                Assert.False(jsonRpcData.IsBatch);

                var jsonRpcItem = jsonRpcData.Item;

                Assert.True(jsonRpcItem.IsValid);

                var jsonRpcMessage = jsonRpcItem.Message;

                Assert.Equal(0L, jsonRpcMessage.Id);
                Assert.Equal("m", jsonRpcMessage.Method);
                Assert.Equal(JsonRpcParametersType.None, jsonRpcMessage.ParametersType);
            }
        }
Exemple #5
0
        public void DeserializeRequestDataT021()
        {
            var jsont = EmbeddedResourceManager.GetString("Assets.v2_spec_02.1_req.json");
            var jrcr  = new JsonRpcContractResolver();
            var jrs   = new JsonRpcSerializer(jrcr);

            var jrmp = new Dictionary <string, Type>
            {
                ["subtrahend"] = typeof(long),
                ["minuend"]    = typeof(long)
            };

            jrcr.AddRequestContract("subtract", new JsonRpcRequestContract(jrmp));

            var jrd = jrs.DeserializeRequestData(jsont);

            Assert.IsFalse(jrd.IsBatch);

            var jrmi = jrd.Item;

            Assert.IsTrue(jrmi.IsValid);

            var jrm = jrmi.Message;

            Assert.AreEqual(4L, jrm.Id);
            Assert.AreEqual("subtract", jrm.Method);
            Assert.AreEqual(JsonRpcParametersType.ByName, jrm.ParametersType);
            Assert.AreEqual(23L, jrm.ParametersByName["subtrahend"]);
            Assert.AreEqual(42L, jrm.ParametersByName["minuend"]);
        }
        public void V1SpecT010DeserializeResponse()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_spec_01.0_res.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            jsonRpcSerializer.ResponseContracts["echo"]  = new JsonRpcResponseContract(typeof(string));
            jsonRpcSerializer.StaticResponseBindings[1L] = "echo";

            var jsonRpcData = jsonRpcSerializer.DeserializeResponseData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.Equal(1L, jsonRpcMessage.Id);
            Assert.IsType <string>(jsonRpcMessage.Result);
            Assert.Equal("Hello JSON-RPC", jsonRpcMessage.Result);
        }
        public void V2SpecT021DeserializeRequest()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_spec_02.1_req.json");
            var jsonRpcSerializer = new Utf8JsonRpcSerializer();

            var jsonRpcSubtractParametersScheme = new Dictionary <string, Type>
            {
                ["subtrahend"] = typeof(long),
                ["minuend"]    = typeof(long)
            };

            jsonRpcSerializer.RequestContracts["subtract"] = new JsonRpcRequestContract(jsonRpcSubtractParametersScheme);

            var jsonRpcData = jsonRpcSerializer.DeserializeRequestData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.Equal(4L, jsonRpcMessage.Id);
            Assert.Equal("subtract", jsonRpcMessage.Method);
            Assert.Equal(JsonRpcParametersType.ByName, jsonRpcMessage.ParametersType);
            Assert.Equal(23L, jsonRpcMessage.ParametersByName["subtrahend"]);
            Assert.Equal(42L, jsonRpcMessage.ParametersByName["minuend"]);
        }
        public void V1SpecT010DeserializeRequest()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_spec_01.0_req.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            jsonRpcSerializer.RequestContracts["echo"] = new JsonRpcRequestContract(new[] { typeof(string) });

            var jsonRpcData = jsonRpcSerializer.DeserializeRequestData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.Equal(1L, jsonRpcMessage.Id);
            Assert.Equal("echo", jsonRpcMessage.Method);
            Assert.Equal(JsonRpcParametersType.ByPosition, jsonRpcMessage.ParametersType);
            Assert.Equal(new object[] { "Hello JSON-RPC" }, jsonRpcMessage.ParametersByPosition);
        }
Exemple #9
0
        public void V1BitcoinT01DeserializeResponse()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_btc_01_res.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            jsonRpcSerializer.ResponseContracts["getblockhash"] = new JsonRpcResponseContract(typeof(string));
            jsonRpcSerializer.StaticResponseBindings["foo"]     = "getblockhash";

            var jsonRpcData = jsonRpcSerializer.DeserializeResponseData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.Equal("foo", jsonRpcMessage.Id);
            Assert.IsType <string>(jsonRpcMessage.Result);
            Assert.Equal("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f", jsonRpcMessage.Result);
        }
Exemple #10
0
        public void V1CoreDeserializeResponseWhenErrorTypeIsInvalid()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_core_error_type_invalid.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            jsonRpcSerializer.ResponseContracts["m"]     = new JsonRpcResponseContract(typeof(string));
            jsonRpcSerializer.StaticResponseBindings[1L] = "m";

            var jsonRpcData = jsonRpcSerializer.DeserializeResponseData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.False(jsonRpcMessage.Success);
            Assert.Equal(1L, jsonRpcMessage.Id);
            Assert.Null(jsonRpcMessage.Result);
            Assert.NotNull(jsonRpcMessage.Error);

            var jsonRpcError = jsonRpcMessage.Error;

            Assert.Equal(default, jsonRpcError.Code);
Exemple #11
0
        public void V1BitcoinT02DeserializeResponse()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_btc_02_res.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            jsonRpcSerializer.ResponseContracts["getblockhash"] = new JsonRpcResponseContract(typeof(string));
            jsonRpcSerializer.StaticResponseBindings["foo"]     = "getblockhash";

            var jsonRpcData = jsonRpcSerializer.DeserializeResponseData(jsonSample);

            Assert.False(jsonRpcData.IsBatch);

            var jsonRpcItem = jsonRpcData.Item;

            Assert.True(jsonRpcItem.IsValid);

            var jsonRpcMessage = jsonRpcItem.Message;

            Assert.Equal("foo", jsonRpcMessage.Id);
            Assert.False(jsonRpcMessage.Success);

            var jsonRpcError = jsonRpcMessage.Error;

            Assert.Equal(-8L, jsonRpcError.Code);
            Assert.Equal("Block height out of range", jsonRpcError.Message);
        }
        public async Task InvokeAsync(string code)
        {
            var requestActualContent       = EmbeddedResourceManager.GetString($"Assets.{code}_req.json");
            var responseExpectedContent    = EmbeddedResourceManager.GetString($"Assets.{code}_res.json");
            var responseExpectedStatusCode = !string.IsNullOrEmpty(responseExpectedContent) ? StatusCodes.Status200OK : StatusCodes.Status204NoContent;

            var serviceProviderMock = new Mock <IServiceProvider>(MockBehavior.Strict);

            serviceProviderMock.Setup(o => o.GetService(typeof(JsonRpcTestHandler1)))
            .Returns(null);
            serviceProviderMock.Setup(o => o.GetService(typeof(IOptions <JsonRpcOptions>)))
            .Returns(null);
            serviceProviderMock.Setup(o => o.GetService(typeof(ILoggerFactory)))
            .Returns(null);

            var environmentMock = new Mock <IWebHostEnvironment>(MockBehavior.Strict);

            environmentMock
            .Setup(o => o.EnvironmentName)
            .Returns(Environments.Production);

            var loggerMock = new Mock <ILogger <JsonRpcMiddleware <JsonRpcTestHandler1> > >(MockBehavior.Loose);

            loggerMock
            .Setup(o => o.IsEnabled(It.IsAny <LogLevel>()))
            .Returns(true);

            var jsonRpcMiddleware = new JsonRpcMiddleware <JsonRpcTestHandler1>(serviceProviderMock.Object, environmentMock.Object, loggerMock.Object);
            var httpContext       = new DefaultHttpContext();

            httpContext.Request.Method      = HttpMethods.Post;
            httpContext.Request.ContentType = "application/json; charset=utf-8";
            httpContext.Request.Headers.Add(HeaderNames.Accept, "application/json; charset=utf-8");
            httpContext.Request.Body  = new MemoryStream(Encoding.UTF8.GetBytes(requestActualContent));
            httpContext.Response.Body = new MemoryStream();

            await jsonRpcMiddleware.InvokeAsync(httpContext, c => Task.CompletedTask);

            Assert.AreEqual(responseExpectedStatusCode, httpContext.Response.StatusCode);

            if (responseExpectedStatusCode == StatusCodes.Status200OK)
            {
                var responseActualContent = default(string);

                httpContext.Response.Body.Position = 0;

                using (var reader = new StreamReader(httpContext.Response.Body))
                {
                    responseActualContent = await reader.ReadToEndAsync();
                }

                Assert.IsFalse(string.IsNullOrEmpty(responseActualContent), "Actual response content is empty");

                var responseActualContentToken   = JToken.Parse(responseActualContent);
                var responseExpectedContentToken = JToken.Parse(responseExpectedContent);

                Assert.IsTrue(JToken.DeepEquals(responseExpectedContentToken, responseActualContentToken), "Actual JSON token differs from expected");
            }
        }
Exemple #13
0
        public IEnumerable <DTOProductOptions> GetProductOptionsList(int product_id)
        {
            string sql = EmbeddedResourceManager.GetString(typeof(ProductsService), DTOPath.DTOProductOptionsSql) + " where po.product_id = @product_id";

            IEnumerable <DTOProductOptions> productOptionList = database.ExucuteQuery <DTOProductOptions>(sql, new { product_id });

            return(productOptionList);
        }
Exemple #14
0
        public IEnumerable <DTOProducts> GetDTOProducts()
        {
            string sql = EmbeddedResourceManager.GetString(typeof(ProductsService), DTOPath.DTOProductSql);

            IEnumerable <DTOProducts> products = database.ExucuteQuery <DTOProducts>(sql);

            return(products);
        }
        public void V2SpecT010SerializeResponse()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_spec_01.0_res.json");
            var jsonRpcSerializer = new Utf8JsonRpcSerializer();
            var jsonRpcMessage    = new JsonRpcResponse(19L, 1L);
            var jsonResult        = jsonRpcSerializer.SerializeResponse(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
        public void V2SpecT010SerializeRequest()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_spec_01.0_req.json");
            var jsonRpcSerializer = new Utf8JsonRpcSerializer();
            var jsonRpcMessage    = new JsonRpcRequest("subtract", 1L, new object[] { 42L, 23L });
            var jsonResult        = jsonRpcSerializer.SerializeRequest(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
        public void V2CoreSerializeRequestWhenIdIsFloat()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_core_id_float_req.json");
            var jsonRpcSerializer = new Utf8JsonRpcSerializer();
            var jsonRpcMessage    = new JsonRpcRequest("m", 1D);
            var jsonResult        = jsonRpcSerializer.SerializeRequest(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
Exemple #18
0
        public async void CoreSerializeResponseAsyncToStreamWhenStreamIsNull()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_core_res.json");
            var jsonRpcSerializer = new JsonRpcSerializer();
            var jsonRpcMessage    = new JsonRpcResponse(0L, 0L);

            await Assert.ThrowsAsync <ArgumentNullException>(() =>
                                                             jsonRpcSerializer.SerializeResponseAsync(jsonRpcMessage, null));
        }
Exemple #19
0
        public void SerializeRequestT010()
        {
            var jsont = EmbeddedResourceManager.GetString("Assets.v2_spec_01.0_req.json");
            var jrs   = new JsonRpcSerializer();
            var jrm   = new JsonRpcRequest(1L, "subtract", new object[] { 42L, 23L });
            var jsonr = jrs.SerializeRequest(jrm);

            JsonRpcSerializerTests.CompareJsonStrings(jsont, jsonr);
        }
Exemple #20
0
        public void SerializeResponseT010()
        {
            var jsont = EmbeddedResourceManager.GetString("Assets.v2_spec_01.0_res.json");
            var jrs   = new JsonRpcSerializer();
            var jrm   = new JsonRpcResponse(1L, 19L);
            var jsonr = jrs.SerializeResponse(jrm);

            JsonRpcSerializerTests.CompareJsonStrings(jsont, jsonr);
        }
        public void SerializeResponseT010()
        {
            var jsont = EmbeddedResourceManager.GetString("Assets.v1_spec_01.0_res.json");
            var jrs   = new JsonRpcSerializer(compatibilityLevel: JsonRpcCompatibilityLevel.Level1);
            var jrm   = new JsonRpcResponse(1L, "Hello JSON-RPC");
            var jsonr = jrs.SerializeResponse(jrm);

            JsonRpcSerializerTests.CompareJsonStrings(jsont, jsonr);
        }
Exemple #22
0
        public void V2CoreSerializeResponseWhenIdIsFloat()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_core_id_float_res.json");
            var jsonRpcSerializer = new JsonRpcSerializer();
            var jsonRpcMessage    = new JsonRpcResponse(string.Empty, 1D);
            var jsonResult        = jsonRpcSerializer.SerializeResponse(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
        public void SerializeRequestT020()
        {
            var jsont = EmbeddedResourceManager.GetString("Assets.v1_spec_02.0_req.json");
            var jrs   = new JsonRpcSerializer(compatibilityLevel: JsonRpcCompatibilityLevel.Level1);
            var jrm   = new JsonRpcRequest(99L, "postMessage", new object[] { "Hello all!" });
            var jsonr = jrs.SerializeRequest(jrm);

            JsonRpcSerializerTests.CompareJsonStrings(jsont, jsonr);
        }
Exemple #24
0
        public void V2CoreSerializeResponseDataWhenHasDataIsTrueAnsIsNull()
        {
            var jsonSample        = EmbeddedResourceManager.GetString("Assets.v2_core_error_has_data_true_null.json");
            var jsonRpcSerializer = new JsonRpcSerializer();
            var jsonRpcError      = new JsonRpcError(0L, "m", null);
            var jsonRpcMessage    = new JsonRpcResponse(jsonRpcError, 1L);
            var jsonResult        = jsonRpcSerializer.SerializeResponse(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
        public IEnumerable <DTOProductOptions> GetProductOptionFiltred(int product_id, HeatingFloorFilter filter)
        {
            string sql = EmbeddedResourceManager.GetString(typeof(ProductsService), DTOPath.DTOProductOptionsSql) + " where po.product_id = @product_id";

            IEnumerable <DTOProductOptions> productOptionList = database.ExucuteQuery <DTOProductOptions>(sql, new { product_id });

            productOptionList = filterService.ApplyHeatingFloorFilter(filter, productOptionList);

            return(productOptionList);
        }
        private static IReadOnlyDictionary <string, byte[]> CreateResourceDictionary()
        {
            var resources = new Dictionary <string, byte[]>(StringComparer.Ordinal);

            foreach (var code in CreateTestCodes())
            {
                resources[code] = Encoding.UTF8.GetBytes(EmbeddedResourceManager.GetString($"Assets.{code}.json"));
            }

            return(resources);
        }
Exemple #27
0
        private static IReadOnlyDictionary <string, string> CreateResourceDictionary()
        {
            var resources = new Dictionary <string, string>(StringComparer.Ordinal);

            foreach (var code in GetResourceCodes())
            {
                resources[code] = EmbeddedResourceManager.GetString($"Assets.{code}.json");
            }

            return(resources);
        }
Exemple #28
0
        public void V1SpecT010SerializeRequest()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_spec_01.0_req.json");

            var jsonRpcSerializer = new JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            var jsonRpcMessage = new JsonRpcRequest("echo", 1L, new object[] { "Hello JSON-RPC" });
            var jsonResult     = jsonRpcSerializer.SerializeRequest(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
        public void V1SpecT020SerializeRequest()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_spec_02.0_req.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            var jsonRpcMessage = new JsonRpcRequest("postMessage", 99L, new object[] { "Hello all!" });
            var jsonResult     = jsonRpcSerializer.SerializeRequest(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }
        public void V1SpecT010SerializeResponse()
        {
            var jsonSample = EmbeddedResourceManager.GetString("Assets.v1_spec_01.0_res.json");

            var jsonRpcSerializer = new Utf8JsonRpcSerializer
            {
                CompatibilityLevel = JsonRpcCompatibilityLevel.Level1
            };

            var jsonRpcMessage = new JsonRpcResponse("Hello JSON-RPC", 1L);
            var jsonResult     = jsonRpcSerializer.SerializeResponse(jsonRpcMessage);

            CompareJsonStrings(jsonSample, jsonResult);
        }