コード例 #1
0
        public async Task SetCreatedAndModifiedTimes()
        {
            SystemClock.AdjustTime(TimeSpan.FromMilliseconds(100));
            DateTime nowUtc   = SystemClock.UtcNow;
            var      employee = await _employeeRepository.AddAsync(EmployeeGenerator.Default);

            Assert.True(employee.CreatedUtc >= nowUtc);
            Assert.True(employee.UpdatedUtc >= nowUtc);

            DateTime createdUtc = employee.CreatedUtc;
            DateTime updatedUtc = employee.UpdatedUtc;

            employee.Name = Guid.NewGuid().ToString();
            SystemClock.Reset();
            employee = await _employeeRepository.SaveAsync(employee);

            Assert.Equal(createdUtc, employee.CreatedUtc);
            Assert.True(updatedUtc < employee.UpdatedUtc, $"Previous UpdatedUtc: {updatedUtc} Current UpdatedUtc: {employee.UpdatedUtc}");
        }