示例#1
0
        public void CreateDocumentsListController_CallTheDetailsAction_EnsuresDefaultModelPropertiesArePresented()
        {
            var docGuid = new Guid("C8420FD7-2AD0-4D34-B8CD-C0636DE5AD09");

            // Arrange
            using (var controller = new DummyDocumentsListController())
            {
                // Act
                var doc = new DummyDocument("App", docGuid)
                {
                    Title = "Doc title"
                };

                var view = controller.Details(doc) as ViewResult;

                var viewModel = view.Model as ContentDetailsViewModel;

                // Assert
                Assert.IsNotNull(viewModel);
                Assert.IsNotNull(viewModel.Item.DataItem == doc);
                Assert.IsTrue(view.ViewBag.Title == doc.Title);
                Assert.IsTrue(view.ViewName == "Detail.DocumentDetails");
                Assert.IsTrue(view.ViewBag.DetailsPageId == Guid.Empty);
                Assert.IsTrue(view.ViewBag.OpenInSamePage);
            }
        }
示例#2
0
        public void Remove_DeletesDocumentFromSession()
        {
            Mock <IDocumentSession> documentSessionMock = new Mock <IDocumentSession>();
            DummyRepository         repository          = new DummyRepository(documentSessionMock.Object);
            DummyDocument           innerDoc            = new DummyDocument();
            DummyEntity             entity = new DummyEntity(innerDoc);

            repository.Remove(entity);

            documentSessionMock.Verify(x => x.Delete(innerDoc), Times.Once());
        }
示例#3
0
        public void Add_SavesDocumentToSession()
        {
            Mock <IDocumentSession> documentSessionMock = new Mock <IDocumentSession>();
            DummyRepository         repository          = new DummyRepository(documentSessionMock.Object);
            DummyDocument           innerDoc            = new DummyDocument();
            DummyEntity             entity = new DummyEntity(innerDoc);

            repository.Add(entity);

            documentSessionMock.Verify(x => x.Store(innerDoc), Times.Once());
        }
示例#4
0
        public async Task <IActionResult> Get()
        {
            //Creates db and collection if they dont exist
            var database = await GetOrCreateDatabaseAsync("test");

            DocumentCollection c1 = await _dbClient.CreateDocumentCollectionIfNotExistsAsync(database.SelfLink, new DocumentCollection { Id = "concurrencyTest" });

            //Creates a random document
            var theId = Guid.NewGuid().ToString();
            var aDoc  = new DummyDocument();

            aDoc.Id = theId;
            await _dbClient.CreateDocumentAsync(_collectionUri, aDoc);

            //Obtains the created document
            Document theDoc = await _dbClient.ReadDocumentAsync(GetDocumentLink(theId));

            if (!theDoc.Id.Equals(theId))
            {
                var err = new Exception("Error reading doc.");
                _telemetry.TrackException(err);
                throw err;
            }

            //Modifies document altering ETag internally
            theDoc.SetPropertyValue("Property1", "modified");
            var result = await _dbClient.ReplaceConcurrentDocumentAsync(GetDocumentLink(theDoc.Id), theDoc);

            if (!HttpStatusCode.OK.Equals(result.StatusCode))
            {
                var err = new Exception("Error modifying doc.");
                _telemetry.TrackException(err);
                throw err;
            }

            //Modifies the same document generating a concurrency exception and handling it
            theDoc.SetPropertyValue("Property1", "modified again");
            var result2 = await _dbClient.ReplaceConcurrentDocumentAsync(GetDocumentLink(theDoc.Id), theDoc).OnConcurrencyException((exception) =>
            {
                _telemetry.TrackEvent("Concurrent handler working!");
                Console.WriteLine($"I got it!! {exception.Message}");
            });

            //Now with Wait (shouldnt be using it but Im testing for deadlocks)
            var result3 = _dbClient.ReplaceConcurrentDocumentAsync(GetDocumentLink(theDoc.Id), theDoc).OnConcurrencyException((exception) =>
            {
                _telemetry.TrackEvent("Concurrent handler working!");
                Console.WriteLine($"I got it!! {exception.Message}");
            });

            result3.Wait();
            return(Ok());
        }
示例#5
0
        public void Load_LoadsDocumentFromSession()
        {
            Mock <IDocumentSession> documentSessionMock = new Mock <IDocumentSession>();
            DummyRepository         repository          = new DummyRepository(documentSessionMock.Object);
            DummyDocument           innerDoc            = new DummyDocument();

            documentSessionMock.Setup(x => x.Load <DummyDocument>("testId")).Returns(innerDoc);

            DummyEntity entity = repository.Load("testId");

            Assert.AreEqual(innerDoc, entity.GetInnerDocument());
        }
示例#6
0
 private void AddDummyDocuments(IDocumentStore documentStore)
 {
     using (var session = documentStore.OpenSession())
     {
         for (int docIndex = 0; docIndex < DummyDocumentCount; docIndex++)
         {
             var newDummyDoc = new DummyDocument()
             {
                 Str = "String #" + docIndex, Num = docIndex
             };
             session.Store(newDummyDoc);
         }
         session.SaveChanges();
     }
 }
        public async Task TheOneAndOnly()
        {
            //Creates db and collection if they dont exist
            var database = await GetOrCreateDatabaseAsync("test");

            DocumentCollection c1 = await _dbClient.CreateDocumentCollectionIfNotExistsAsync(database.SelfLink, new DocumentCollection { Id = "concurrencyTest" });

            //Creates a random document
            var theId = Guid.NewGuid().ToString();
            var aDoc  = new DummyDocument();

            aDoc.Id = theId;
            await _dbClient.CreateDocumentAsync(_collectionUri, aDoc);

            //Obtains the created document
            Document theDoc = await _dbClient.ReadDocumentAsync(GetDocumentLink(theId));

            Assert.Equal(theDoc.Id, theId);

            //Modifies document altering ETag internally
            theDoc.SetPropertyValue("Property1", "modified");
            var result = await _dbClient.ReplaceConcurrentDocumentAsync(GetDocumentLink(theDoc.Id), theDoc);

            Assert.Equal(result.StatusCode, HttpStatusCode.OK);

            //Modifies the same document generating a concurrency exception and handling it
            theDoc.SetPropertyValue("Property1", "modified again");
            var result2 = await _dbClient.ReplaceConcurrentDocumentAsync(GetDocumentLink(theDoc.Id), theDoc).OnConcurrencyException((exception) =>
            {
                Console.WriteLine($"I got it!! {exception.Message}");
            });

            //Now with Wait (shouldnt be using it but Im testing for deadlocks)
            var result3 = _dbClient.ReplaceConcurrentDocumentAsync(GetDocumentLink(theDoc.Id), theDoc).OnConcurrencyException((exception) =>
            {
                Console.WriteLine($"I got it!! {exception.Message}");
            });

            result3.Wait();
        }
示例#8
0
 private bool Equals(DummyDocument other)
 {
     return string.Equals(Str, other.Str) && Num == other.Num;
 }
示例#9
0
 private void AddDummyDocuments(IDocumentStore documentStore)
 {
     using (var session = documentStore.OpenSession())
     {
         for (int docIndex = 0; docIndex < DummyDocumentCount; docIndex++)
         {
             var newDummyDoc = new DummyDocument() {Str = "String #" + docIndex, Num = docIndex};
             session.Store(newDummyDoc);
         }
         session.SaveChanges();
     }
 }
示例#10
0
 private bool Equals(DummyDocument other)
 {
     return(string.Equals(Str, other.Str) && Num == other.Num);
 }