示例#1
0
        public async Task Given_TemperatureRepository_When_GettingTemperatureRecordsOfAUser_Then_AllRecordsOfThatUserShouldBeReturnedAsync()
        {
            await RunOnDatabaseAsync(async sut =>
            {
                //Arrange
                var repo    = new TemperatureRepository(sut);
                var userId  = Guid.NewGuid();
                var records = new List <TemperatureRecord>
                {
                    new TemperatureRecord
                    {
                        Id     = Guid.NewGuid(),
                        UserId = userId,
                        Value  = 1,
                        Time   = new DateTime(2017, 11, 20, 11, 21, 1)
                    },
                    new TemperatureRecord
                    {
                        Id     = Guid.NewGuid(),
                        UserId = Guid.NewGuid(),
                        Value  = 2,
                        Time   = new DateTime(2017, 11, 20, 11, 21, 1)
                    }
                };

                //Act
                foreach (var record in records)
                {
                    await repo.AddAsync(record);
                }
                await repo.SaveChangesAsync();

                //Assert
                var results = await repo.GetByUserIdAsync(userId);
                results.Count.Should().Be(1);
            });
        }