Esempio n. 1
0
        public void GetPet_ParametersMatchExpectedValues()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PetDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var currentUser = new Mock <ICurrentUserService>();

            currentUser.SetupGet(c => c.UserId).Returns("testuser");
            var currentUserService = currentUser.Object;

            var fakePet = new FakePet {
            }.Generate();

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Pets.AddRange(fakePet);
                context.SaveChanges();

                var service = new PetRepository(context, new SieveProcessor(sieveOptions));

                //Assert
                var petById = service.GetPet(fakePet.PetId);
                petById.PetId.Should().Be(fakePet.PetId);
                petById.Name.Should().Be(fakePet.Name);
                petById.Type.Should().Be(fakePet.Type);
            }
        }