public long SaveNote(UserSelectedContext catalogInfo, ListItemModel detail) { NotesListHeader header = _headerRepo.GetHeadersForCustomer(catalogInfo); if (header == null) { // Create a new header for the customer header = new NotesListHeader() { BranchId = catalogInfo.BranchId, CustomerNumber = catalogInfo.CustomerId }; header.Id = _headerRepo.Save(header); } long detailId = 0; var noteDetail = _detailRepo.Get(header.Id, detail.ItemNumber); if (noteDetail != null) { detailId = noteDetail.Id; } return(_detailRepo.Save(detail.ToListModel(header.Id, detailId))); }
public void GoodHeader_ReturnsGoodHeaderId() { // arrange int expected = 4; NotesListHeader header = MakeHeader(); INotesHeadersListRepository repo = MakeRepo(); // act long headerId = repo.Save(header); // assert headerId.Should() .Be(expected); }
public void NullCustomerNumber_ThrowsSqlException() { // arrange NotesListHeader header = new NotesListHeader { BranchId = "FRT", CreatedUtc = new DateTime(2017, 6, 30, 16, 32, 0, DateTimeKind.Utc), ModifiedUtc = new DateTime(2017, 6, 30, 16, 33, 0, DateTimeKind.Utc) }; INotesHeadersListRepository repo = MakeRepo(); // act Action act = () => { repo.Save(header); }; // assert act.Should().Throw <SqlException>(); }
public void GoodHeader_SavesCorrectCustomerNumber() { // arrange string expected = "200321"; UserSelectedContext context = new UserSelectedContext() { CustomerId = "200321", BranchId = "FRT" }; NotesListHeader header = MakeHeader(); INotesHeadersListRepository repo = MakeRepo(); // act var headerId = repo.Save(header); var results = repo.GetHeadersForCustomer(context); // assert results.CustomerNumber .Should() .Be(expected); }
public void GoodHeader_DoesNotUseSetModifiedUtc() { // arrange DateTime expected = new DateTime(2017, 6, 30, 16, 33, 0, DateTimeKind.Utc); UserSelectedContext context = new UserSelectedContext() { CustomerId = "200321", BranchId = "FRT" }; NotesListHeader header = MakeHeader(); INotesHeadersListRepository repo = MakeRepo(); // act var headerId = repo.Save(header); var results = repo.GetHeadersForCustomer(context); // assert results.ModifiedUtc .Should() .NotBe(expected); }