コード例 #1
0
        public void UpdateRowTGetPrimaryKeyThrowsErrorButStillLogs()
        {
            var objT = new IQueryableType {
                Id = 15
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.GetPrimaryKeys(objT)).Throws(new NullReferenceException());
            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.write, "table1"))
            .Returns(resource.Object);

            try
            {
                var result = tableOperations.UpdateRow("conn1", "table1", objT, loggingService);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Assert.AreEqual(1, loggingService.LogCount);
                Assert.AreEqual("PUT", loggingService.ApiRequests.First().RequestType);
            }
        }
コード例 #2
0
        public void ExecuteParams()
        {
            var obj       = new Dictionary <string, object>();
            var objParams = new IQueryableType()
            {
                Id = 34
            };

            IDictionary <string, object> usedParams = null;

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.ExecuteProc(It.IsAny <IDictionary <string, object> >()))
            .Callback <IDictionary <string, object> >(c => usedParams = c)
            .Returns(obj);


            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.read, "proc1"))
            .Returns(resource.Object);

            var results = storedProcedureOperations.Execute("conn1", "proc1", objParams, loggingService);

            Assert.AreEqual(1, loggingService.LogCount);
            Assert.AreEqual("POST", loggingService.ApiRequests.First().RequestType);
            Assert.AreEqual(obj, results);
            Assert.AreEqual("34", usedParams["Id"].ToString());
        }
コード例 #3
0
        public void UpdateRow()
        {
            JToken obj = new JObject
            {
                ["Id"] = 15
            };

            var objT = new IQueryableType {
                Id = 15
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.GetPrimaryKeys(obj)).Returns(new object[] { "15" });
            resource.Setup(c => c.UpdateResourceRecordById(obj, new object[] { "15" }))
            .Returns(objT);

            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.write, "table1"))
            .Returns(resource.Object);

            var result = tableOperations.UpdateRow("conn1", "table1", obj, loggingService);

            Assert.AreEqual(1, loggingService.LogCount);
            Assert.AreEqual("PUT", loggingService.ApiRequests.First().RequestType);
            Assert.AreEqual(15, ((IQueryableType)result).Id);
        }
コード例 #4
0
        public void DeleteRow()
        {
            var objT = new IQueryableType {
                Id = 15
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.DeleteResourceRecordById(new object[] { "15" }))
            .Returns(objT);

            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.delete, "table1"))
            .Returns(resource.Object);

            var result = tableOperations.DeleteRow("conn1", "table1", "15");

            Assert.AreEqual(0, loggingService.LogCount);
            Assert.AreEqual(15, ((IQueryableType)result).Id);
        }
コード例 #5
0
        public void CreateNewRowT()
        {
            var objT = new IQueryableType {
                Id = 15
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.CreateNewResourceRecord(objT))
            .Returns(objT);

            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.write, "table1"))
            .Returns(resource.Object);

            var result = tableOperations.CreateNewRow("conn1", "table1", objT);

            Assert.AreEqual(0, loggingService.LogCount);
            Assert.AreEqual(15, result.Id);
        }
コード例 #6
0
        public void GetByIdT()
        {
            var resultsList = new IQueryableType {
                Id = 1
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.GetResourceRecordById <IQueryableType>(new object[] { "1" }, new Dictionary <string, string>()))
            .Returns(resultsList);

            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.read, "table1"))
            .Returns(resource.Object);

            var results = tableOperations.GetById <IQueryableType>("conn1", "table1", "1");

            Assert.AreEqual(1, results.Id);
            Assert.IsInstanceOfType(results, typeof(IQueryableType));
        }
コード例 #7
0
        public void UpdateRowT()
        {
            var objT = new IQueryableType {
                Id = 15
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.GetPrimaryKeys(objT)).Returns(new object[] { "15" });
            resource.Setup(c => c.UpdateResourceRecordById(objT, new object[] { "15" }))
            .Returns(objT);

            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.write, "table1"))
            .Returns(resource.Object);

            var result = tableOperations.UpdateRow("conn1", "table1", objT);

            Assert.AreEqual(0, loggingService.LogCount);
            Assert.AreEqual(15, result.Id);
        }
コード例 #8
0
        public void GetById()
        {
            var resultsList = new IQueryableType {
                Id = 1
            };

            var resource = new Mock <IOperationResource>();

            resource.Setup(c => c.GetResourceRecordById(new object[] { "1" }))
            .Returns(resultsList);

            resourceFactoryMock.Setup(c => c.GetResource("conn1", OperationType.read, "table1"))
            .Returns(resource.Object);

            var results = tableOperations.GetById("conn1", "table1", "1");

            Assert.AreEqual(0, loggingService.LogCount);

            Assert.AreEqual(1, ((IQueryableType)results).Id);
            Assert.IsInstanceOfType(results, typeof(object));
            Assert.IsInstanceOfType(results, typeof(IQueryableType));
        }