Пример #1
0
        public async Task AddJobThrowsOnEmptyUserId()
        {
            var service = new ShiftService(_client, TestDb, TestContainer);
            var fixture = new Fixture();

            var testJob = fixture.Create <NewJob>();

            var func = new Func <Task>(() => service.AddJob(string.Empty, testJob));
            await func.Should().ThrowAsync <ArgumentException>();
        }
Пример #2
0
        public async Task AddJobThrowsOnNullJob()
        {
            var service = new ShiftService(_client, TestDb, TestContainer);
            var fixture = new Fixture();

            var userId = fixture.Create <string>();

            var func = new Func <Task>(() => service.AddJob(userId, null));
            await func.Should().ThrowAsync <ArgumentException>();
        }
Пример #3
0
        public async Task AddJobReturnsFalseIfShiftDoesNotExist()
        {
            var service = new ShiftService(_client, TestDb, TestContainer);
            var fixture = new Fixture();

            var testJob = fixture.Create <NewJob>();
            var userId  = fixture.Create <string>();

            var res = await service.AddJob(userId, testJob);

            res.Should().BeFalse();
        }
Пример #4
0
        public async Task AddJobReturnsTrueIfJobAdded()
        {
            var service = new ShiftService(_client, TestDb, TestContainer);
            var fixture = new Fixture();

            var userId    = fixture.Create <string>();
            var testShift = fixture.Build <Shift>()
                            .With(s => s.UserId, userId)
                            .Without(s => s.Jobs)
                            .Create();
            var testJob = fixture.Build <NewJob>()
                          .With(j => j.Shift, testShift.Id)
                          .Create();
            var expectedJob = new Job
            {
                Age            = testJob.Age,
                BlueLights     = testJob.BlueLights,
                Category       = testJob.Category,
                Drove          = testJob.Drove,
                Gender         = testJob.Gender,
                Notes          = testJob.Notes,
                Outcome        = testJob.Outcome,
                ReflectionFlag = testJob.ReflectionFlag
            };

            await _client.CreateDatabaseIfNotExistsAsync(TestDb);

            await _client.GetDatabase(TestDb).CreateContainerIfNotExistsAsync(TestContainer, "/userId");

            await _client.GetContainer(TestDb, TestContainer).CreateItemAsync(testShift, new PartitionKey(userId));

            var res = await service.AddJob(userId, testJob);

            res.Should().BeTrue();

            var container     = _client.GetContainer(TestDb, TestContainer);
            var shiftResponse = await container.ReadItemAsync <Shift>(testShift.Id, new PartitionKey(userId));

            var shift = shiftResponse.Resource;

            shift.Jobs.Should().ContainSingle();
            shift.Jobs.Single().Should().BeEquivalentTo(expectedJob);
        }