Exemple #1
0
        public async Task Create_WithPlant_ShouldSavePlantInDatabase()
        {
            using (var context = new RamosiContext(options))
            {
                // Arrange
                var plant = new PlantBuilder()
                            .WithName("Plant")
                            .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithNotes("This is a characteristic"))
                            .WithPlantCollection(new List <PlantCollection>
                {
                    new PlantCollectionBuilder().WithNickname("Part of the collection")
                });

                var repo = new PlantRepository(context);

                // Act
                repo.Create(plant);
                await repo.SaveChanges();

                // Assert
                Assert.AreEqual(1, context.Plants.Count());
                var created = context.Plants.First();

                Assert.AreEqual("Plant", created.Name);
                Assert.AreEqual("This is a characteristic", created.PlantCharacteristic.Notes);
                Assert.AreEqual(1, created.PlantCollection.Count);
                Assert.AreEqual("Part of the collection", created.PlantCollection.First().Nickname);
            }
        }
Exemple #2
0
        public void Create_WithNullPlant_ShouldNotSavePlant()
        {
            using (var context = new RamosiContext(options))
            {
                // Arrange
                var repo = new PlantRepository(context);

                // Act
                Assert.Throws <ArgumentNullException>(() => repo.Create(null),
                                                      "Entity of type Plant cannot be null");

                // Assert
                Assert.IsFalse(context.Plants.Any());
            }
        }