public async Task DataContext_EntityCreation_StoresComplexObjectProperties() { var book = await BookPocosHelper.CreateBookPocoAsync(persistToDynamoDb : false, publisher : new BookPoco.PublisherDto { Title = "O’Reilly Media", Address = "Sebastopol, CA" }); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); await this.Context.SubmitChangesAsync(); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); Assert.AreEqual(book.Publisher.ToString(), storedBookPoco.Publisher.ToString(), "Complex object properties are not equal"); storedBookPoco.Publisher = new BookPoco.PublisherDto { Title = "O’Reilly Media", Address = "Illoqortormiut, Greenland" }; this.Context.SubmitChanges(); var storedBookPoco2 = booksTable.Find(book.Name, book.PublishYear); Assert.AreEqual(storedBookPoco2.Publisher.ToString(), storedBookPoco.Publisher.ToString(), "Complex object properties are not equal after updating"); }
public async Task DataContext_EntityRemoval_DoesNotThrowAnyExceptionsIfRecordToRemoveDoesNotExist() { var book = await BookPocosHelper.CreateBookPocoAsync(persistToDynamoDb : false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.RemoveOnSubmit(book); await this.Context.SubmitChangesAsync(); }
// [ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "cannot be added, because entity with that key already exists", MatchType = MessageMatch.Contains)] public async Task DataContext_EntityCreation_ThrowsExceptionWhenEntityAlreadyExistsInDynamoDbButWasNeverQueriedInCurrentContext() { var book = await BookPocosHelper.CreateBookPocoAsync(popularityRating : BookPoco.Popularity.Average); book.PopularityRating = BookPoco.Popularity.High; var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); await this.Context.SubmitChangesAsync(); }
public async Task DataContext_EntityCreation_PersistsRecordToDynamoDb() { var book = await BookPocosHelper.CreateBookPocoAsync(persistToDynamoDb : false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); await this.Context.SubmitChangesAsync(); var storedBookPoco = await booksTable.FindAsync(book.Name, book.PublishYear); Assert.IsNotNull(storedBookPoco); }
public async Task DataContext_EntityRemoval_RemovesExistingRecordFromDynamoDb() { var book = await BookPocosHelper.CreateBookPocoAsync(); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.RemoveOnSubmit(book); await this.Context.SubmitChangesAsync(); var storedBookPocosCount = booksTable.Count(storedBookPoco => storedBookPoco.Name == book.Name); Assert.AreEqual(0, storedBookPocosCount, "Record was not deleted"); }
public void DataContext_EntityCreation_ThrowsExceptionWhenEntityPreviouslyStoredInDynamoDbWasQueriedInCurrentContext() { var book = BookPocosHelper.CreateBookPoco(popularityRating: BookPoco.Popularity.Average); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.Find(book.Name, book.PublishYear); book.PopularityRating = BookPoco.Popularity.High; booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); }
public void DataContext_EntityCreation_PersistsRecordToDynamoDb() { var book = BookPocosHelper.CreateBookPoco(persistToDynamoDb: false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); Assert.IsNotNull(storedBookPoco); }
public void DataContext_UpdateEntity_UpdatesRecordWhenOldRecordIsNull() { var book = BookPocosHelper.CreateBookPoco(popularityRating: BookPoco.Popularity.Average); var booksTable = this.Context.GetTable <BookPoco>(); book.PopularityRating = BookPoco.Popularity.High; ((ITableCudOperations)booksTable).UpdateEntity(book, null); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); Assert.AreEqual(book.PopularityRating, storedBookPoco.PopularityRating, "Record was not updated"); }
public void DataContext_EntityCreation_ThrowsExceptionWhenTryingToAddSameEntityTwice() { var book = BookPocosHelper.CreateBookPoco(popularityRating: BookPoco.Popularity.Average, persistToDynamoDb: false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); book.PopularityRating = BookPoco.Popularity.High; booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); }
public async Task DataContext_UpdateEntity_UpdatesRecordWhenOldRecordDoesNotMatchNewRecord() { var book = await BookPocosHelper.CreateBookPocoAsync(popularityRating : BookPoco.Popularity.Average); var booksTable = this.Context.GetTable <BookPoco>(); var storedBookPoco = await booksTable.FindAsync(book.Name, book.PublishYear); storedBookPoco.PopularityRating = BookPoco.Popularity.High; ((ITableCudOperations)booksTable).UpdateEntity(storedBookPoco, book); var updatedBookPoco = await booksTable.FindAsync(book.Name, book.PublishYear); Assert.AreEqual(storedBookPoco.PopularityRating, updatedBookPoco.PopularityRating, "Record was not updated"); }
public async Task DataContext_EntityCreation_ThrowsExceptionWhenEntityPreviouslyStoredInDynamoDbWasQueriedInCurrentContext() { var book = await BookPocosHelper.CreateBookPocoAsync(popularityRating : BookPoco.Popularity.Average); var booksTable = this.Context.GetTable <BookPoco>(); await booksTable.FindAsync(book.Name, book.PublishYear); book.PopularityRating = BookPoco.Popularity.High; booksTable.InsertOnSubmit(book); (await Should.ThrowAsync <InvalidOperationException>(() => this.Context.SubmitChangesAsync())).Message.ShouldContain( "cannot be added, because entity with that key already exists" ); }
public void DataContext_EntityModification_UpdatesRecordWithNewValues() { var book = BookPocosHelper.CreateBookPoco(popularityRating: BookPoco.Popularity.Average, persistToDynamoDb: false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); book.PopularityRating = BookPoco.Popularity.High; this.Context.SubmitChanges(); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); Assert.AreEqual(book.PopularityRating, storedBookPoco.PopularityRating, "Record was not updated"); }
public async Task DataContext_EntityCreation_ThrowsExceptionWhenTryingToAddSameEntityTwice() { var book = await BookPocosHelper.CreateBookPocoAsync(popularityRating : BookPoco.Popularity.Average, persistToDynamoDb : false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); await this.Context.SubmitChangesAsync(); book.PopularityRating = BookPoco.Popularity.High; booksTable.InsertOnSubmit(book); (await Should.ThrowAsync <InvalidOperationException>(() => this.Context.SubmitChangesAsync())).Message.ShouldContain( "cannot be added, because entity with that key already exists" ); }
public void DataContext_EntityModification_UpdateRecordWithNewArray() { var book = BookPocosHelper.CreateBookPoco(rentingHistory: null, persistToDynamoDb: false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); storedBookPoco.RentingHistory = new List <string>() { "non-empty array" }; this.Context.SubmitChanges(); var storedBookPocoAfterModification = booksTable.Find(book.Name, book.PublishYear); CollectionAssert.AreEquivalent(storedBookPoco.RentingHistory, storedBookPocoAfterModification.RentingHistory); }
public void DataContext_EntityModification_UpdateShouldNotAffectFieldsModifiedFromOutside() { var book = BookPocosHelper.CreateBookPoco(popularityRating: BookPoco.Popularity.Average, persistToDynamoDb: false); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); this.Context.SubmitChanges(); // Update record from outside of DataTable BookPocosHelper.CreateBookPoco(book.Name, book.PublishYear, numPages: 15); book.PopularityRating = BookPoco.Popularity.High; this.Context.SubmitChanges(); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); Assert.AreEqual(book.PopularityRating, storedBookPoco.PopularityRating, "Record was not updated"); Assert.AreEqual(book.NumPages, 15, "Update has erased changes from outside"); }
public async Task DataContext_EntityCreation_StoresComplexObjectListProperties() { var book = await BookPocosHelper.CreateBookPocoAsync(persistToDynamoDb : false, reviews : new List <BookPoco.ReviewDto> { new BookPoco.ReviewDto { Author = "Beavis", Text = "Cool" }, new BookPoco.ReviewDto { Author = "Butt-head", Text = "This sucks!" } }); var booksTable = this.Context.GetTable <BookPoco>(); booksTable.InsertOnSubmit(book); await this.Context.SubmitChangesAsync(); var storedBookPoco = booksTable.Find(book.Name, book.PublishYear); var expectedSequence1 = string.Join(", ", book.ReviewsList.Select(r => r.ToString()).OrderBy(s => s)); var actualSequence1 = string.Join(", ", storedBookPoco.ReviewsList.Select(r => r.ToString()).OrderBy(s => s)); Assert.AreEqual(expectedSequence1, actualSequence1, "Complex object list properties are not equal"); }
public static void ClassInit() { BooksHelper.StartSession(); BookPocosHelper.StartSession(); }
public static async Task ClassClean() { await BooksHelper.CleanSessionAsync(); await BookPocosHelper.CleanSessionAsync(); }
public static async Task ClassInit() { await BooksHelper.StartSessionAsync(); await BookPocosHelper.StartSessionAsync(); }
public static void ClassClean() { BooksHelper.CleanSession(); BookPocosHelper.CleanSession(); }