Exemplo n.º 1
0
        public void CanCreateMockContext()
        {
            var mockContext = new StorageContextMockFactory().CreateStorageContextMock();
            var context     = mockContext.Object;

            Assert.NotNull(context);
        }
Exemplo n.º 2
0
        public void RegisterClean_Should_AddRecordInEntityMap()
        {
            var mockContext = new StorageContextMockFactory().CreateStorageContextMock();
            var context     = mockContext.Object;
            var musician    = new Musician("John Doe", "Anonymous", "*****@*****.**");

            Assert.DoesNotContain(musician, context.Entities);
            context.RegisterClean(musician);
            Assert.Contains(musician, context.Entities);
        }
Exemplo n.º 3
0
        public void RegisterNew_WhenObjectIsInRemovedEntities_ShouldThrowException()
        {
            var mockContext = new StorageContextMockFactory().CreateStorageContextMock();
            var context     = mockContext.Object;
            var musician    = new Musician("John Doe", "Anonymous", "*****@*****.**");

            Assert.DoesNotContain(musician, context.Entities);
            context.RegisterRemoved(musician);
            Assert.Contains(musician, context.Entities);
            Assert.Throws <InvalidOperationException>(() => context.RegisterNew(musician));
        }
Exemplo n.º 4
0
        public async Task Get_Should_RetrieveEntityFromEntityMap()
        {
            var mockContext = new StorageContextMockFactory().CreateStorageContextMock();
            var context     = mockContext.Object;
            var musician    = new Musician("John Doe", "Anonymous", "*****@*****.**");

            context.RegisterNew(musician);
            var loadedMusician = await context.GetAsync <Musician>(musician.PartitionKey, musician.RowKey, CancellationToken.None);

            Assert.Equal(musician, loadedMusician, new TableEntityEqualityComparer <Musician>());
        }
Exemplo n.º 5
0
        public async Task SaveChangesAsync_ShouldCallDeleteRemoedEntitiesAsync()
        {
            var mockContext = new StorageContextMockFactory().CreateStorageContextMock();
            var context     = mockContext.Object;
            await context.SaveChangesAsync();

            mockContext.Protected().Verify("DeleteRemovedEntitiesAsync", Times.Once(),
                                           ItExpr.IsAny <CancellationToken>(),
                                           ItExpr.IsAny <TableRequestOptions>(),
                                           ItExpr.IsAny <OperationContext>());
        }
Exemplo n.º 6
0
        public void RegisterMultipleDifferentEntitiesWithSameKeys_Should_AddRecordsInEntityMap()
        {
            var mockContext = new StorageContextMockFactory().CreateStorageContextMock();
            var context     = mockContext.Object;
            var musician    = new Musician("John Doe", "Anonymous", "*****@*****.**");
            var bandTeacher = new BandTeacher("John Doe", "Anonymous", "*****@*****.**");

            Assert.DoesNotContain(musician, context.Entities);
            Assert.DoesNotContain(bandTeacher, context.Entities);
            context.RegisterNew(musician);
            context.RegisterNew(bandTeacher);
            Assert.Contains(musician, context.Entities);
            Assert.Contains(bandTeacher, context.Entities);
        }