コード例 #1
0
        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");
        }
コード例 #2
0
        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();
        }
コード例 #3
0
//        [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();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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");
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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");
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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");
        }
コード例 #11
0
        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"
                );
        }
コード例 #12
0
        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");
        }
コード例 #13
0
        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"
                );
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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");
        }
コード例 #16
0
        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");
        }
コード例 #17
0
 public static void ClassInit()
 {
     BooksHelper.StartSession();
     BookPocosHelper.StartSession();
 }
コード例 #18
0
        public static async Task ClassClean()
        {
            await BooksHelper.CleanSessionAsync();

            await BookPocosHelper.CleanSessionAsync();
        }
コード例 #19
0
        public static async Task ClassInit()
        {
            await BooksHelper.StartSessionAsync();

            await BookPocosHelper.StartSessionAsync();
        }
コード例 #20
0
 public static void ClassClean()
 {
     BooksHelper.CleanSession();
     BookPocosHelper.CleanSession();
 }