public IEnumerable <string> Get() { DocumentDb db = new DocumentDb(); var rs = db.GetSensorMessages(); yield return(Newtonsoft.Json.JsonConvert.SerializeObject(rs)); }
public async Task UpsertDocument_UpdateDocument_IsUpdatedCorrectly() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); var person = new PersonTest { Id = Guid.Parse(documentId), PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personEnvelope = new DocumentBase <PersonTest> { VM = person }; await db.UpsertDocument(CollectionId, documentId, personEnvelope); personEnvelope = await db.ReadDocument <PersonTest>(CollectionId, documentId); personEnvelope.VM.Name = "Fred Flintstone"; personEnvelope.VM.Age = 88; await db.UpsertDocument(CollectionId, documentId, personEnvelope); // Assert var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId); doc.VM.Age.Should().Be(88); doc.VM.Name.Should().Be("Fred Flintstone"); doc.VM.PersonId.Should().Be(person.PersonId); }
public async Task ReadDocument_DocumentExists_ReturnDocumentIsCorrect() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); var person = new PersonTest { PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personEnvelope = new DocumentBase <PersonTest> { VM = person }; await db.UpsertDocument(CollectionId, documentId, personEnvelope); // Act var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId); // Assert doc.VM.Age.Should().Be(person.Age); doc.VM.Name.Should().Be(person.Name); doc.VM.PersonId.Should().Be(person.PersonId); doc.ETag.Should().NotBe(string.Empty); }
public DocumentObserverChatClient(DocumentClientConfig config, DocumentDb <Message> db) { this.config = config; this.db = db; this.settings = IocServices.Resolve <ISettings>(); }
public async Task UpsertDocument_NewDocument_IsStoredCorrectly() { // Arrange var db = new DocumentDb(location, key, database); var id = Guid.NewGuid(); var person = new PersonTest() { PersonId = id, Name = "Barney Rubble", Age = 87 }; var personEnvelope = new DocumentBase <PersonTest> { VM = person, ETag = Guid.NewGuid().ToString() }; // Act await db.UpsertDocument(CollectionId, id.ToString(), personEnvelope); // Assert var doc = await db.ReadDocument <PersonTest>(CollectionId, id.ToString()); doc.VM.Age.Should().Be(87); doc.VM.Name.Should().Be("Barney Rubble"); doc.VM.PersonId.Should().Be(person.PersonId); }
public async Task Init(Application app) { IocServices.AddSingleton <ISettings>(new Settings()); var config = new DocumentClientConfig { Collection = "TestCollection", Database = "TestDatabase", Url = "https://localhost:8081", //DocumentDb Emulator Token Key = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", LeaseCollection = "TestCollectionLease", OldMessagesCount = 10, PollDelay = TimeSpan.FromSeconds(1) }; var uri = new Uri(config.Url); var key = config.Key; var client = new DocumentClient(uri, key); var db = new DocumentDb <Message>(client, config.Database, config.Collection, config.LeaseCollection); var chatCleint = new MockObserverChatClient(config, db); await chatCleint.Start(); IocServices.AddSingleton <IChatClient>(chatCleint); app.MainPage = new XamarinChatWithCosmosOnly.MainPage(); }
public void OneTimeSetUp() { _logger = new Logger(); _dataCreator = new TestDataCreator(); var lockDb = new DistributedLockDb(_logger); var docDb = new DocumentDb(_logger); lockDb.InitializeDatabase(); docDb.InitializeDatabase(); }
private async Task <DocumentDb> SetupMultiplePersons() { var db = new DocumentDb(location, key, database); var personA = new PersonTest { PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87, Id = new Guid("C9FCD0EB-E5F3-439D-BA4D-093E692046C0") }; var personAEnvelope = new DocumentBase <PersonTest> { VM = personA, ETag = Guid.NewGuid().ToString() }; var personB = new PersonTest { PersonId = Guid.NewGuid(), Name = "Wilma Flintstone", Age = 88, Id = Guid.NewGuid() }; var personBEnvelope = new DocumentBase <PersonTest> { VM = personB, ETag = Guid.NewGuid().ToString() }; var personC = new PersonTest { PersonId = Guid.NewGuid(), Name = "Wilma Flintstone", Age = 66, Id = Guid.Empty }; var personCEnvelope = new DocumentBase <PersonTest> { VM = personC, ETag = Guid.NewGuid().ToString() }; var personD = new PersonTest { PersonId = Guid.NewGuid(), Name = "Wilma Flintstone", Age = 66, Id = Guid.NewGuid() }; var personDEnvelope = new DocumentBase <PersonTest> { VM = personD, ETag = Guid.NewGuid().ToString() }; await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personAEnvelope); await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personBEnvelope); await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personCEnvelope); await db.UpsertDocument(CollectionId, Guid.NewGuid().ToString(), personDEnvelope); return(db); }
public async Task ReadAll_CollectionIdKnownButEmpty_ReturnsEmptyCollection() { // Arrange var db = new DocumentDb(location, key, database); // Act var doc = await db.ReadAll <PersonTest>(CollectionId); // Assert doc.Should().BeEmpty(); }
public void IsDocumentInCollection_DocumentIdIsNull_ThrowsException(string documentId) { // Arrange var db = new DocumentDb(location, key, database); // Act var ex = Record.Exception(() => db.DocumentExists(CollectionId, documentId)); //Assert ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public async Task ReadAll_CollectionIdIsNull_ThrowsException(string collectionId) { // Arrange var db = new DocumentDb(location, key, database); // Act var ex = await Record.ExceptionAsync(() => db.ReadAll <PersonTest>(collectionId)); //Assert ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public async Task DeleteDocument_DocumentNotExists_NoExceptionThrown() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); // Act var ex = await Record.ExceptionAsync(() => db.DeleteDocument(CollectionId, documentId)); // Assert ex.Should().BeNull(); }
public async Task DeleteCollection_NullCollectionId_ThrowsException(string collectionId) { // Arrange var db = new DocumentDb(location, key, database); // Act var ex = await Record.ExceptionAsync(() => db.DeleteCollection(collectionId)); //Assert ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public DocumentDbTest() { location = ConfigurationManager.AppSettings["DocumentDbUrl"]; key = ConfigurationManager.AppSettings["DocumentDbAuthKey"]; database = ConfigurationManager.AppSettings["DocumentDbDatabaseId"]; var db = new DocumentDb(location, key, database); db.ClearCollection(NewCollectionId).Wait(); db.ClearCollection(CollectionId).Wait(); db.CreateCollection(CollectionId).Wait(); }
public void IsDocumentInCollection_DocumentDoesNotExist_ReturnsFalse() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); // Act var exists = db.DocumentExists(CollectionId, documentId); // Assert exists.Should().BeFalse(); }
public async Task <bool> Delete(int id) { if (id == 214213232) { DocumentDb db = new DocumentDb(); return(await db.ClearDocumentCollectionAsync(CollectionId)); } else { return(false); } }
public async Task ReadDocument_DocumentNotExists_ReturnsNull() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); // Act var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId); // Assert doc.Should().BeNull(); }
public async Task DeleteDocument_CollectionIdIsNull_ThrowsException(string collectionId) { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); // Act var ex = await Record.ExceptionAsync(() => db.DeleteDocument(collectionId, documentId)); //Assert ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public async Task CreateCollection_NewCollectionNameProvided_NewCollectionCreated() { // Arrange var db = new DocumentDb(location, key, database); // Act await db.CreateCollection(NewCollectionId); // Assert var exists = await db.CollectionExists(NewCollectionId); exists.Should().BeTrue(); }
public async static Task RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new string[] { "SendGridEventWebhook.Controllers" } ); // Create stored procedure on DocumentDb DocumentDb ddb = DocumentDb.GetInstance(); await ddb.Init(); }
public async Task UpsertDocument_NullItem_ThrowsException() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); DocumentBase <PersonTest> personEnvelope = null; // Act var ex = await Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, documentId, personEnvelope)); // Assert ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public async Task UpsertDocument_NullDocumentId_ThrowsException(string documentId) { // Arrange var db = new DocumentDb(location, key, database); var person = new PersonTest { PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personEnvelope = new DocumentBase <PersonTest> { VM = person, ETag = Guid.NewGuid().ToString() }; // Act var ex = await Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, documentId, personEnvelope)); //Assert ex.Should().NotBeNull(); ex.Should().BeOfType <ArgumentNullException>(); }
public async Task IsDocumentInCollection_DocumentDoesExist_ReturnsTrue() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); var person = new PersonTest { PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personEnvelope = new DocumentBase <PersonTest> { VM = person }; await db.UpsertDocument(CollectionId, documentId, personEnvelope); // Act var exists = db.DocumentExists(CollectionId, documentId); // Assert exists.Should().BeTrue(); }
public async Task UpsertDocument_TwoNewDocumentsSameIdDifferentEtag_OnlyOneIsStored() { // Arrange var db = new DocumentDb(location, key, database); var id = Guid.NewGuid(); var personA = new PersonTest() { Id = id, PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personB = new PersonTest() { Id = id, PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personAEnvelope = new DocumentBase <PersonTest> { VM = personA }; var personBEnvelope = new DocumentBase <PersonTest> { VM = personB }; // Act var taskForPersonA = db.UpsertDocument(CollectionId, id.ToString(), personAEnvelope); var taskForPersonB = db.UpsertDocument(CollectionId, id.ToString(), personBEnvelope); // Assert //We don't care about exception now we just waiting for tasks to finish await Record.ExceptionAsync(() => Task.WhenAll(taskForPersonA, taskForPersonB)); var persons = await db.Query <PersonTest>(CollectionId, new Dictionary <string, object>() { { "Id", personA.Id } }); persons.Count().Should().Be(1); }
public async Task UpsertDocument_UpdateDocumentConncurrently_ThrowsException() { // Arrange var db = new DocumentDb(location, key, database); var documentId = Guid.NewGuid().ToString(); var person = new PersonTest { PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87, }; var personEnvelope = new DocumentBase <PersonTest> { VM = person }; await db.UpsertDocument(CollectionId, documentId, personEnvelope); personEnvelope = await db.ReadDocument <PersonTest>(CollectionId, documentId); var newChange = new DocumentBase <PersonTest> { VM = person }; newChange.VM.Name = "Change"; newChange.ETag = personEnvelope.ETag; personEnvelope.VM.Name = "Fred Flintstone"; personEnvelope.VM.Age = 88; await db.UpsertDocument(CollectionId, documentId, personEnvelope); var exception = await Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, documentId, newChange)); // Assert exception.Should().NotBeNull(); exception.Should().BeOfType <ConcurrencyException>(); exception.Message.Should().Contain("One of the specified pre-condition is not met"); }
public async Task UpsertDocument_TwoNewDocuments_OneThrowsConcurrencyException() { // Arrange var db = new DocumentDb(location, key, database); var id = Guid.NewGuid(); var personA = new PersonTest() { Id = id, PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personB = new PersonTest() { Id = id, PersonId = Guid.NewGuid(), Name = "Barney Rubble", Age = 87 }; var personAEnvelope = new DocumentBase <PersonTest> { VM = personA, ETag = id.ToString() }; var personBEnvelope = new DocumentBase <PersonTest> { VM = personB, ETag = id.ToString() }; // Act var taskForPersonA = db.UpsertDocument(CollectionId, id.ToString(), personAEnvelope); var taskForPersonB = db.UpsertDocument(CollectionId, id.ToString(), personBEnvelope); // Assert var exception = await Record.ExceptionAsync(() => Task.WhenAll(taskForPersonA, taskForPersonB)); exception.Should().NotBeNull(); exception.Should().BeOfType <ConcurrencyException>(); }
public Consumer(DistributedLockDb lockDb, DocumentDb documentDb, Logger logger) { _lockDb = lockDb; _documentDb = documentDb; _logger = logger; }
public MockObserverChatClient(DocumentClientConfig config, DocumentDb <Message> db) : base(config, db) { }
private void SetupDatabases() { _documentDb = new DocumentDb(_config, "Grouper Service"); _logDb = new LogDb(_config); }
public RepositoryBase(DocumentDb db) { _db = db; }