public async Task TestAfterSaveChangesAsync()
        {
            using (ShimsContext.Create())
            {
                var connectionString = "connection string";
                var queueName        = "value";
                appSettings.Add(AppSettings.SEARCH_INDEX_QUEUE_NAME_KEY, queueName);
                connectionStrings.Add(new ConnectionStringSettings(AppSettings.AZURE_WEB_JOBS_STORAGE_KEY, connectionString));
                var created = new List <SimpleEntity>();
                created.Add(new SimpleEntity
                {
                    Id = 1,
                });

                saveAction.CreatedEntities.AddRange(created);
                saveAction.DocumentKeys[created.First()] = new DocumentKey(SimpleEntityConfiguration.SIMPLE_ENTITY_DOCUMENT_TYPE_ID, created.First().Id);
                var fakeQueue = new Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueue
                {
                    CreateIfNotExistsAsync = () =>
                    {
                        return(Task.FromResult <bool>(true));
                    },
                    AddMessageAsyncCloudQueueMessage = (msg) =>
                    {
                        var deserializedMessage = JsonConvert.DeserializeObject <IndexDocumentBatchMessage>(msg.AsString);
                        Assert.AreEqual(1, deserializedMessage.CreatedDocuments.Count());
                        Assert.AreEqual(0, deserializedMessage.DeletedDocuments.Count());
                        Assert.AreEqual(0, deserializedMessage.ModifiedDocuments.Count());
                        return(Task.FromResult <object>(null));
                    },
                };

                Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueueClient.AllInstances.GetQueueReferenceString = (client, qName) =>
                {
                    Assert.AreEqual(queueName, qName);
                    return(fakeQueue);
                };

                Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount.AllInstances.CreateCloudQueueClient = (acct) =>
                {
                    return(new Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueueClient());
                };

                Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount.ParseString = (s) =>
                {
                    Assert.AreEqual(connectionString, s);
                    return(new Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount());
                };

                var entityEntry = new System.Data.Entity.Infrastructure.Fakes.ShimDbEntityEntry <SimpleEntity>
                {
                };
                System.Data.Entity.Fakes.ShimDbContext.AllInstances.EntryOf1M0 <SimpleEntity>((ctx, add) =>
                {
                    return(entityEntry);
                });

                await saveAction.AfterSaveChangesAsync((DbContext)context);
            }
        }
        public async Task TestAfterSaveChangesAsync_NoMessages()
        {
            using (ShimsContext.Create())
            {
                var createIfNotExistsCalled = false;
                var addMessageCalled        = false;
                var connectionString        = "connection string";
                var queueName = "value";
                appSettings.Add(AppSettings.SEARCH_INDEX_QUEUE_NAME_KEY, queueName);
                connectionStrings.Add(new ConnectionStringSettings(AppSettings.AZURE_WEB_JOBS_STORAGE_KEY, connectionString));
                var fakeQueue = new Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueue
                {
                    CreateIfNotExistsAsync = () =>
                    {
                        createIfNotExistsCalled = true;
                        return(Task.FromResult <bool>(true));
                    },
                    AddMessageAsyncCloudQueueMessage = (msg) =>
                    {
                        addMessageCalled = true;
                        return(Task.FromResult <object>(null));
                    },
                };

                Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueueClient.AllInstances.GetQueueReferenceString = (client, qName) =>
                {
                    Assert.AreEqual(queueName, qName);
                    return(fakeQueue);
                };

                Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount.AllInstances.CreateCloudQueueClient = (acct) =>
                {
                    return(new Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueueClient());
                };

                Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount.ParseString = (s) =>
                {
                    Assert.AreEqual(connectionString, s);
                    return(new Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount());
                };

                await saveAction.AfterSaveChangesAsync((DbContext)context);

                Assert.IsFalse(createIfNotExistsCalled);
                Assert.IsFalse(addMessageCalled);
            }
        }
        public void TestAfterSaveChanges_NoMessages()
        {
            using (ShimsContext.Create())
            {
                var createIfNotExistsCalled = false;
                var addMessageCalled        = false;
                var connectionString        = "connection string";
                var queueName = "value";
                appSettings.Add(AppSettings.SEARCH_INDEX_QUEUE_NAME_KEY, queueName);
                connectionStrings.Add(new ConnectionStringSettings(AppSettings.AZURE_WEB_JOBS_STORAGE_KEY, connectionString));
                var fakeQueue = new Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueue
                {
                    CreateIfNotExistsQueueRequestOptionsOperationContext = (opt, ctx) =>
                    {
                        createIfNotExistsCalled = true;
                        return(true);
                    },
                    AddMessageCloudQueueMessageNullableOfTimeSpanNullableOfTimeSpanQueueRequestOptionsOperationContext = (msg, ttl, delay, options, ctx) =>
                    {
                        addMessageCalled = true;
                    },
                };

                Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueueClient.AllInstances.GetQueueReferenceString = (client, qName) =>
                {
                    Assert.AreEqual(queueName, qName);
                    return(fakeQueue);
                };

                Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount.AllInstances.CreateCloudQueueClient = (acct) =>
                {
                    return(new Microsoft.WindowsAzure.Storage.Queue.Fakes.ShimCloudQueueClient());
                };

                Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount.ParseString = (s) =>
                {
                    Assert.AreEqual(connectionString, s);
                    return(new Microsoft.WindowsAzure.Storage.Fakes.ShimCloudStorageAccount());
                };

                saveAction.AfterSaveChanges((DbContext)context);
                Assert.IsFalse(createIfNotExistsCalled);
                Assert.IsFalse(addMessageCalled);
            }
        }