Exemple #1
0
        public async Task JsonPatchAllAsync()
        {
            var utcNow    = SystemClock.UtcNow;
            var employees = new List <Employee> {
                EmployeeGenerator.Generate(ObjectId.GenerateNewId(utcNow.AddDays(-1)).ToString(), createdUtc: utcNow.AddDays(-1), companyId: "1", yearsEmployed: 0),
                EmployeeGenerator.Generate(createdUtc: utcNow, companyId: "1", yearsEmployed: 0),
                EmployeeGenerator.Generate(createdUtc: utcNow, companyId: "2", yearsEmployed: 0),
            };

            await _employeeRepository.AddAsync(employees, o => o.ImmediateConsistency());

            var patch = new PatchDocument(new ReplaceOperation {
                Path = "name", Value = "Patched"
            });
            await _employeeRepository.PatchAsync(employees.Select(l => l.Id).ToArray(), new Models.JsonPatch(patch), o => o.ImmediateConsistency());

            var results = await _employeeRepository.GetAllByCompanyAsync("1");

            Assert.Equal(2, results.Documents.Count);
            foreach (var document in results.Documents)
            {
                Assert.Equal("1", document.CompanyId);
                Assert.Equal("patched", document.Name);
            }
        }
Exemple #2
0
        public async Task GetByCompanyAsync()
        {
            var employee1 = await _employeeRepository.AddAsync(EmployeeGenerator.Generate(age: 19, companyId: EmployeeGenerator.DefaultCompanyId));

            var employee2 = await _employeeRepository.AddAsync(EmployeeGenerator.Generate(age: 20));

            await _client.RefreshAsync();

            var results = await _employeeRepository.GetAllByCompanyAsync(employee1.CompanyId);

            Assert.Equal(1, results.Total);
            Assert.Equal(employee1, results.Documents.First());

            results = await _employeeRepository.GetAllByCompanyAsync(employee2.CompanyId);

            Assert.Equal(1, results.Total);
            Assert.Equal(employee2, results.Documents.First());

            Assert.Equal(1, await _employeeRepository.GetCountByCompanyAsync(employee1.CompanyId));
            await _employeeRepository.RemoveAsync(employee1, false);

            await _client.RefreshAsync();

            Assert.Equal(1, await _employeeRepository.CountAsync());
            Assert.Equal(0, await _employeeRepository.GetCountByCompanyAsync(employee1.CompanyId));
        }