Exemple #1
0
        public void Create_AnyAuditedEntity_EntityCreated()
        {
            // Arrange
            var entityToCreate = new AnyAuditedEntity
            {
                AnyString = "AnyString"
            };
            var expected = new AnyAuditedEntity
            {
                AnyString = "AnyString",
                CreatedBy = 1
            };
            var expectedTime = DateTime.UtcNow;

            // Act
            repository.Create(entityToCreate, 1);
            dbContext.SaveChanges();

            // Assert
            var actual = dbContext.AnyAuditedEntities.First();

            actual.Should().BeEquivalentTo(expected, opts => opts.Excluding(x => x.Id).Excluding(x => x.CreatedAt));
            actual.CreatedAt.Should().BeCloseTo(expectedTime);
        }
        public void GetAll_Default_ReturnsAll()
        {
            // Arrange
            var expected = new[]
            {
                new AnyEntity
                {
                    Id        = 1,
                    AnyString = "Any"
                },
                new AnyEntity
                {
                    Id        = 2,
                    AnyString = "Any"
                }
            };

            dbContext.AnyEntities.AddRange(expected);
            dbContext.SaveChanges();

            // Act
            var actual = repository.GetAll();

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }