Пример #1
0
        public async Task CannotAddSameTwice_ShouldReturnTheSameId()
        {
            RepositoryDatabase database        = new RepositoryDatabase(Settings);
            string             organizationOne = Guid.NewGuid().ToString();
            string             repoOne         = Guid.NewGuid().ToString();
            RepositoryInfo     repo            = null;
            RepositoryInfo     repo2           = null;

            Task t1 = Task.Run(async() =>
            {
                repo = await database.UpsertUpdate(new RepositoryInfo()
                {
                    OrganizationName = organizationOne,
                    RepositoryName   = repoOne
                }
                                                   ).ConfigureAwait(false);
            });
            Task t2 = Task.Run(async() =>
            {
                repo2 = await database.UpsertUpdate(new RepositoryInfo()
                {
                    OrganizationName = organizationOne,
                    RepositoryName   = repoOne
                }
                                                    ).ConfigureAwait(false);
            });
            //add both repos pretty much at the same time
            await Task.WhenAll(t1, t2);

            repo.Should().NotBeNull("Because it should have been created by the tasks invoke");

            repo.Id.Should().NotBe(ObjectId.Empty);
            repo.Id.Should().Be(repo2.Id, "because the same repository already exists");
        }