Beispiel #1
0
        public void TestData()
        {
            while (true)
            {
                List<PersonTest> ps = LocalDB<PersonTest>.Select();
                if (ps.Any())
                {
                    PersonTest p = ps[0];
                    p.Age += 1;
                    if (p.Age > 50)
                    {
                        break;
                    }
                    p.Insert();
                }
                else
                {
                    PersonTest p = new PersonTest { Name = "zhoulin", Age = 0 };
                    p.Insert();
                }
                Thread.Sleep(500);
            }

            TData();
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public void SellAccomodationShouldInformUserWhenAccomodationIsAlreadySold()
        {
            //Init
            var clientModel = new SellAccomodationModel
            {
                AccomodationNumber = AccomodationTest.GetAccomodation().Number,
                PersonId           = "1"
            };

            var person              = PersonTest.GetPersonWithoutId();
            var accomodation        = AccomodationTest.GetAccomodation();
            var personService       = Substitute.For <PersonService>();
            var clientService       = Substitute.For <ClientService>();
            var prospectService     = Substitute.For <ProspectService>();
            var accomodationService = Substitute.For <AccomodationService>();
            var personQuery         = Substitute.For <PersonQueryExtended>();
            var accomodationQuery   = Substitute.For <AccomodationQueryExtended>();
            var controller          = new ControllerImpl(personService, clientService, prospectService,
                                                         accomodationService, personQuery, accomodationQuery);

            clientService
            .When(c => c.SellAccomodation(person, accomodation))
            .Do(c => { throw new AccomodationAlreadySoldException(); });

            //Act
            var message = controller.SellAccomodation(clientModel);

            //Assert
            Check.That(message).IsEqualTo("Accomodation Sold !");
        }
Beispiel #4
0
        public static DbContextOptions <PersonDataContext> GetDBOptions(this PersonTest clientTest)
        {
            DbContextOptionsBuilder <PersonDataContext> optionsBuilder = new DbContextOptionsBuilder <PersonDataContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning));
            return(optionsBuilder.Options);
        }
Beispiel #5
0
        public async Task UpsertDocument_NewDocument_IsStoredCorrectly()
        {
            // Arrange
            var db         = new MongoDb(ConnectionString, DatabaseId);
            var documentId = Guid.NewGuid().ToString();
            var person     = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87
            };

            var personEnvelope = new DocumentBase <PersonTest>()
            {
                VM = person
            };
            // Act
            await db.UpsertDocument(CollectionId, documentId, personEnvelope);

            // Assert
            var doc = await db.ReadDocument <PersonTest>(CollectionId, documentId);

            doc.VM.Age.Should().Be(87);
            doc.VM.Name.Should().Be("Barney Rubble");
            doc.VM.PersonId.Should().Be(person.PersonId);
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            //BookRe

            //var test = new XmlTest();
            //test.Test();
            //test.Test2();
            //test.Test3();
            //test.Test4();

            var testPerson = new PersonTest();

            testPerson.Test();

            /*
             * var lambdaTest = new LambdaTest();
             * lambdaTest.CallMethod();
             * lambdaTest.CreateMethod();
             * lambdaTest.MemberCopy();
             * lambdaTest.PropertyEquals();
             * lambdaTest.LoopPrint();
             * lambdaTest.ExpSqlIn();
             */


            Console.Read();
        }
Beispiel #7
0
        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 async Task <IActionResult> PutPersonTest(int id, PersonTest personTest)
        {
            if (id != personTest.PersonId)
            {
                return(BadRequest());
            }

            _context.Entry(personTest).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PersonTestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #9
0
        public void TestData()
        {
            while (true)
            {
                List <PersonTest> ps = LocalDB <PersonTest> .Select();

                if (ps.Any())
                {
                    PersonTest p = ps[0];
                    p.Age += 1;
                    if (p.Age > 50)
                    {
                        break;
                    }
                    p.Insert();
                }
                else
                {
                    PersonTest p = new PersonTest {
                        Name = "zhoulin", Age = 0
                    };
                    p.Insert();
                }
                Thread.Sleep(500);
            }

            TData();
        }
Beispiel #10
0
        public async Task DeleteDocument_DocumentExists_DocumentIsDeleted()
        {
            // Arrange
            var db         = new MongoDb(ConnectionString, DatabaseId);
            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
            await db.DeleteDocument(CollectionId, documentId);

            var exists = db.DocumentExists(CollectionId, documentId);

            // Assert
            exists.Should().BeFalse();
        }
Beispiel #11
0
        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 ActionResult Update([DataSourceRequest] DataSourceRequest request,
                                   PersonTest person, Dictionary <string, object>[] jobs)
        {
            if (ModelState.IsValid)
            {
                var currPerson = db.People.GetById(person.Id);
                currPerson.Name        = person.Name;
                currPerson.BirthYear   = person.BirthYear;
                currPerson.BirthPlace  = person.BirthPlace;
                currPerson.Description = person.Description;
                currPerson.Image       = new Image()
                {
                    Url = person.ImageUrl
                };

                var personJobs = new HashSet <Job>();

                if (jobs != null)
                {
                    foreach (var job in jobs)
                    {
                        foreach (var obj in job)
                        {
                            if (obj.Key == "Id")
                            {
                                int jobId   = Convert.ToInt32(((string[])obj.Value)[0]);
                                var currJob = db.Jobs.GetById(jobId);
                                personJobs.Add(currJob);
                            }
                        }
                    }

                    if (personJobs.Count <= currPerson.Jobs.Count)
                    {
                        currPerson.Jobs = personJobs;
                    }
                    else
                    {
                        foreach (var job in personJobs)
                        {
                            if (!currPerson.Jobs.Contains(job))
                            {
                                currPerson.Jobs.Add(job);
                            }
                        }
                    }
                }
                else
                {
                    currPerson.Jobs = personJobs;
                }

                db.SaveChanges();

                person.JobsAsString = string.Join(", ", personJobs.Select(x => x.Name));
            }

            return(Json(new[] { person }.ToDataSourceResult(request, ModelState)));
        }
Beispiel #13
0
        public void ClientShouldNotAcceptNullAccomodation()
        {
            Accomodation accomodation = null;

            Action action = () => new Client(PersonTest.GetPersonWithoutId(), accomodation);

            Check.ThatCode(action).Throws <ArgumentNullException>();
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        private async Task <MongoDb> SetupMultiplePersons()
        {
            var db = new MongoDb(ConnectionString, DatabaseId);

            var personA = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Barney Rubble",
                Age      = 87,
                HomeID   = new Guid("F79E323E-7BCD-4865-8BE7-5F674BE650CE")
            };
            var personAEnvelope = new MongoDb.MongoDocumentWrapper <PersonTest> {
                VM = personA, ETag = Guid.NewGuid().ToString()
            };
            var personB = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Wilma Flintstone",
                Age      = 88,
                HomeID   = new Guid("F79E323E-7BCD-4865-8BE7-5F674BE650CE")
            };
            var personBEnvelope = new MongoDb.MongoDocumentWrapper <PersonTest> {
                VM = personB, ETag = Guid.NewGuid().ToString()
            };
            var personC = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Wilma Flintstone",
                Age      = 66,
                HomeID   = new Guid("F79E323E-7BCD-4865-8BE7-5F674BE650CE")
            };
            var personCEnvelope = new MongoDb.MongoDocumentWrapper <PersonTest> {
                VM = personC, ETag = Guid.NewGuid().ToString()
            };
            var personD = new PersonTest
            {
                PersonId = Guid.NewGuid(),
                Name     = "Wilma Flintstone",
                Age      = 66,
                HomeID   = new Guid("F79E323E-7BCD-4865-8BE7-5F674BE650CE")
            };
            var personDEnvelope = new MongoDb.MongoDocumentWrapper <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);
        }
Beispiel #16
0
        public void When_search_is_value_should_be_valid()
        {
            var command = new PersonTest()
            {
                FirstName = "fistName",
                LastName  = "lastName"
            };

            var result = _sut.Validate(command);

            Assert.IsTrue(result.IsValid);
        }
Beispiel #17
0
        public IActionResult AddPersonTests(PersonTestCreateModel personTest)
        {
            PersonTest persontest = new PersonTest
            {
                StrName    = personTest.StrName,
                StrAddress = personTest.StrAddress,
                Age        = personTest.Age
            };

            _personTestData.AddPersonTest(persontest);

            return(Ok());
        }
Beispiel #18
0
        public void When_first_name_is_white_space_should_have_validation_error()
        {
            var command = new PersonTest()
            {
                FirstName = "  ",
                LastName  = "lastName"
            };

            var result = _sut.Validate(command);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(nameof(command.FirstName), result.Errors.FirstOrDefault().PropertyName);
        }
        public ProspectServiceImplTest()
        {
            this.person = PersonTest.GetPerson(Option.None <PersonFirstName>(),
                                               Option.None <PersonName>(), Option.None <PersonEmail>());
            this.personRepository = Substitute.For <PersonRepository>();

            this.accomodation = AccomodationTest.GetAccomodation();

            this.personQuery = Substitute.For <PersonQuery>();
            this.personQuery.Exist(this.person).Returns(true);
            this.personQuery.IsProspectOnThisAccomodation(this.person, this.accomodation).Returns(false);

            this.accomodationQuery = Substitute.For <AccomodationQuery>();
            this.accomodationQuery.Exist(this.accomodation).Returns(true);

            this.prospectService = new ProspectServiceImpl(this.personRepository, this.personQuery, this.accomodationQuery);
        }
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, PersonTest person,
                                   Dictionary <string, object>[] jobs)
        {
            if (ModelState.IsValid)
            {
                var currPerson = new Person
                {
                    Name        = person.Name,
                    BirthPlace  = person.BirthPlace,
                    BirthYear   = person.BirthYear,
                    Description = person.Description,
                    Image       = new Image()
                    {
                        Url = person.ImageUrl
                    }
                };

                if (jobs != null)
                {
                    foreach (var job in jobs)
                    {
                        foreach (var obj in job)
                        {
                            if (obj.Key == "Id")
                            {
                                int jobId   = Convert.ToInt32(((string[])obj.Value)[0]);
                                var currJob = db.Jobs.GetById(jobId);
                                currPerson.Jobs.Add(currJob);
                            }
                        }
                    }
                }

                db.People.Add(currPerson);
                db.SaveChanges();

                person.JobsAsString = string.Join(", ", currPerson.Jobs.Select(x => x.Name));
            }

            return(Json(new[] { person }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult <PersonTest> > PostPersonTest(PersonTest personTest)
        {
            _context.PersonTest.Add(personTest);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PersonTestExists(personTest.PersonId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetPersonTest", new { id = personTest.PersonId }, personTest));
        }
Beispiel #22
0
        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>();
        }
Beispiel #23
0
        public async Task UpsertDocument_UpsertTwoNewDocuments_OneSucceeds()
        {
            // Arrange
            var db = new MongoDb(ConnectionString, DatabaseId);
            //The two persons are meant to be the same one updated from different sources, hence the same id.
            var personId = Guid.NewGuid();
            var personA  = new PersonTest
            {
                PersonId = personId,
                Name     = "Person A",
                Age      = 1
            };
            var personB = new PersonTest
            {
                PersonId = personId,
                Name     = "Person B",
                Age      = 2
            };

            var personAEnvelope = new DocumentBase <PersonTest> {
                VM = personA
            };
            var personBEnvelope = new DocumentBase <PersonTest> {
                VM = personB
            };

            // Act
            var taskForUpsertA = Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, personA.PersonId.ToString(), personAEnvelope));
            var taskForUpsertB = Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, personB.PersonId.ToString(), personBEnvelope));

            // Assert"
            await Task.WhenAll(taskForUpsertA, taskForUpsertB);

            var items = await db.Query <PersonTest>(CollectionId, new Dictionary <string, object>
            {
                { "PersonId", personId }
            });

            items.Count().Should().Be(1);
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        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();
        }
Beispiel #26
0
        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");
        }
Beispiel #27
0
        public async Task UpsertDocument_UpdateDocumentConcurrently_ThrowsException()
        {
            // Arrange
            var db         = new MongoDb(ConnectionString, DatabaseId);
            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>();
        }
Beispiel #28
0
        public async Task UpsertDocument_UpsertTwoNewDocuments_OneFailsWithConcurrencyException()
        {
            // Arrange
            var db = new MongoDb(ConnectionString, DatabaseId);
            //The two persons are meant to be the same one updated from different sources, hence the same id.
            var personId = Guid.NewGuid();
            var personA  = new PersonTest
            {
                PersonId = personId,
                Name     = "Person A",
                Age      = 1
            };
            var personB = new PersonTest
            {
                PersonId = personId,
                Name     = "Person B",
                Age      = 2
            };

            var personAEnvelope = new DocumentBase <PersonTest> {
                VM = personA
            };
            var personBEnvelope = new DocumentBase <PersonTest> {
                VM = personB
            };
            var taskForUpsertA = Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, personA.PersonId.ToString(), personAEnvelope));
            var taskForUpsertB = Record.ExceptionAsync(() => db.UpsertDocument(CollectionId, personB.PersonId.ToString(), personBEnvelope));

            await Task.WhenAll(taskForUpsertA, taskForUpsertB);

            //The .Result below is fine because we have already awaited normally on line above
            var exceptions = new[] { taskForUpsertA.Result, taskForUpsertB.Result };

            // Assert"
            exceptions.Count(x => x != null).Should().Be(1);
            exceptions.Single(x => x != null).Should().BeOfType <ConcurrencyException>();
        }
Beispiel #29
0
        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>();
        }
Beispiel #30
0
 public void PersonPropertyShouldBeTheSameAsConstructorParameter()
 {
     Check.That(this.client.Person).IsEqualTo(PersonTest.GetPersonWithoutId());
 }
Beispiel #31
0
        public ClientTest()
        {
            var person = PersonTest.GetPersonWithoutId();

            this.client = new Client(person, AccomodationTest.GetAccomodation());
        }