public List <InvoiceComment> GetCommentByInvoiceId(int InvoiceId) { List <InvoiceComment> List = new List <InvoiceComment>(); DataProvider.ExecuteCmd(GetConnection, "dbo.Comments_GetInvoiceCommentsByInvoiceID" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@InvoiceId", InvoiceId); }, map : delegate(IDataReader reader, short set) { InvoiceComment Comment = new InvoiceComment(); int startingIndex = 0; Comment.InvoiceId = reader.GetSafeInt32(startingIndex++); Comment.CommentId = reader.GetSafeInt32(startingIndex++); Comment.CommentText = reader.GetSafeString(startingIndex++); Comment.FirstName = reader.GetSafeString(startingIndex++); Comment.LastName = reader.GetSafeString(startingIndex++); Comment.CreatedDate = reader.GetSafeDateTime(startingIndex++); Comment.DisplayToClient = reader.GetSafeInt32(startingIndex++); List.Add(Comment); }); return(List); }
public async Task Create_WithCorrectValues_ShouldCreateCommentAndReturnCorrectValues() { //arrange var comment = new InvoiceComment { InvoiceId = 7506691, Created = DateTime.Parse("0001-01-01T00:00:00", CultureInfo.InvariantCulture), Comment = "Test Comment", Public = true, ActionKey = CommentType.Comment, ByClient = true, UserId = 52821, ClientId = 3722360 }; var expectedResult = new InvoiceComment { Id = 31327675, Created = DateTime.Parse("2020-07-30T10:42:51+02:00", CultureInfo.InvariantCulture), Comment = "Test Comment", ActionKey = CommentType.Comment, Public = true, ByClient = true, UserId = 52821, ClientId = 3722360, InvoiceId = 7506691 }; var expectedRequestUri = new Uri("/api/invoice-comments", UriKind.Relative); const string expectedRequestBody = "{\"invoice-comment\":{\"id\":\"0\",\"created\":\"0001-01-01T00:00:00.0000000\",\"comment\":\"Test Comment\",\"actionkey\":\"COMMENT\",\"public\":\"True\",\"by_client\":\"True\",\"user_id\":\"52821\",\"email_id\":\"\",\"client_id\":\"3722360\",\"invoice_id\":\"7506691\"}}"; const string responseBody = "{\"invoice-comment\":{\"id\":\"31327675\",\"created\":\"2020-07-30T10:42:51+02:00\",\"comment\":\"Test Comment\",\"actionkey\":\"COMMENT\",\"public\":\"1\",\"by_client\":\"1\",\"user_id\":\"52821\",\"email_id\":\"\",\"client_id\":\"3722360\",\"invoice_id\":\"7506691\",\"customfield\":\"\"}}"; var http = A.Fake <IHttpClient>(); A.CallTo(() => http.PostAsync(expectedRequestUri, expectedRequestBody, A <CancellationToken> .Ignored)) .Returns(Task.FromResult(responseBody)); var sut = GetSystemUnderTest(http); Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); //act var result = await sut.CreateCommentAsync(comment); // assert A.CallTo(() => http.PostAsync(expectedRequestUri, expectedRequestBody, A <CancellationToken> .Ignored)) .MustHaveHappenedOnceExactly(); result.Should().BeEquivalentTo(expectedResult); }
public async Task GetCommentById_ShouldReturnCorrectValues() { //arrange var expectedRequestUri = new Uri("/api/invoice-comments/4662801", UriKind.Relative); const string responseBody = "{\"invoice-comment\":{\"id\":\"4662801\",\"created\":\"2015-06-04T10:04:54+02:00\",\"comment\":\"Rechnung erstellt.\",\"actionkey\":\"CREATE\",\"public\":\"0\",\"by_client\":\"0\",\"user_id\":\"52821\",\"email_id\":\"\",\"client_id\":\"\",\"invoice_id\":\"1322225\",\"customfield\":\"\"}}"; var expectedResult = new InvoiceComment { Id = 4662801, Created = DateTime.Parse("2015-06-04T10:04:54+02:00", CultureInfo.InvariantCulture), Comment = "Rechnung erstellt.", ActionKey = CommentType.Create, Public = false, ByClient = false, UserId = 52821, EmailId = null, ClientId = null, InvoiceId = 1322225 }; var http = A.Fake <IHttpClient>(); A.CallTo(() => http.GetAsync(expectedRequestUri, A <CancellationToken> .Ignored)) .Returns(Task.FromResult(responseBody)); var sut = GetSystemUnderTest(http); //act var result = await sut.GetCommentByIdAsync(4662801); //assert A.CallTo(() => http.GetAsync(expectedRequestUri, A <CancellationToken> .Ignored)) .MustHaveHappenedOnceExactly(); result.Should().BeEquivalentTo(expectedResult); }
public void UpdateCommentDisplaySetting(InvoiceComment model) { DataProvider.ExecuteNonQuery(GetConnection, "dbo.Comments_InvoiceCommentsXrefUpdate" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@CommentID", model.CommentId); paramCollection.AddWithValue("@DisplayToClient", model.DisplayToClient); }); }
public async Task Create_WithInvalidApiKey_ShouldThrowNotAuthorizedException() { //arrange var http = A.Fake <IHttpClient>(); var sut = GetSystemUnderTest(http); var expectedRequestUri = new Uri("/api/invoice-comments", UriKind.Relative); A.CallTo(() => http.PostAsync(expectedRequestUri, A <string> .Ignored, A <CancellationToken> .Ignored)) .ThrowsAsync(ExceptionFactory.CreateNotAuthorizedException); var comment = new InvoiceComment { InvoiceId = 1, Comment = "asdf" }; await Assert.ThrowsAsync <NotAuthorizedException>(() => sut.CreateCommentAsync(comment)); A.CallTo(() => http.PostAsync(expectedRequestUri, A <string> .Ignored, A <CancellationToken> .Ignored)) .MustHaveHappenedOnceExactly(); }