Пример #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();
        }
Пример #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);
        }
Пример #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 !");
        }
Пример #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);
        }
Пример #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);
        }
Пример #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();
        }
Пример #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());
        }
Пример #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();
        }
Пример #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();
        }
Пример #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);
        }
Пример #12
0
        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)));
        }
Пример #13
0
        public void ClientShouldNotAcceptNullAccomodation()
        {
            Accomodation accomodation = null;

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

            Check.ThatCode(action).Throws <ArgumentNullException>();
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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());
        }
Пример #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);
        }
Пример #20
0
        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));
        }
Пример #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>();
        }
Пример #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);
        }
Пример #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);
        }
Пример #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();
        }
Пример #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");
        }
Пример #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>();
        }
Пример #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>();
        }
Пример #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>();
        }
Пример #30
0
 public void PersonPropertyShouldBeTheSameAsConstructorParameter()
 {
     Check.That(this.client.Person).IsEqualTo(PersonTest.GetPersonWithoutId());
 }
Пример #31
0
        public ClientTest()
        {
            var person = PersonTest.GetPersonWithoutId();

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