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); } }
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()); }
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); }
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); }
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); }
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)); }
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); }
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)); }