Esempio n. 1
0
        public void UpdateSchool()
        {
            // Setup
            var schoolRepository = new SchoolRepository(SchoolMachineContext);
            var newSchool        = new School
            {
                Name = "Test School 2"
            };

            schoolRepository.CreateSchool(newSchool).Wait();
            var savedSchool = schoolRepository.GetSchoolById(newSchool.Id).Result;

            Assert.IsNotNull(savedSchool, string.Format("School {0} was not saved in the database", newSchool.Id));
            Assert.IsTrue(savedSchool.Name == newSchool.Name, string.Format("School({0}).Name was not saved in the database", newSchool.Id));

            // Test Logic
            newSchool.Name = "Test School 2 - Modified";
            schoolRepository.UpdateSchool(savedSchool, newSchool).Wait();

            // Assertions
            var retrievedSchool = schoolRepository.GetSchoolById(savedSchool.Id).Result;

            Assert.IsFalse(retrievedSchool.IsEmptyObject(), string.Format("Updated school({0}) was not retrieved from the database", newSchool.Id));
            Assert.IsTrue(retrievedSchool.Name == newSchool.Name, string.Format("School({0}).Name was not updated in the database", newSchool.Id));

            // Teardown
            schoolRepository.DeleteSchool(savedSchool).Wait();
            var shouldBeDeletedSchool = schoolRepository.GetSchoolById(newSchool.Id).Result;

            Assert.IsTrue(shouldBeDeletedSchool.IsEmptyObject(), string.Format("School({0}) was not deleted from the database", newSchool.Id));
        }
Esempio n. 2
0
        public async Task <School> CreateSchool([Service] SchoolRepository schoolRepository,
                                                [Service] ITopicEventSender eventSender, string schoolName)
        {
            var newSchool = new School
            {
                Name = schoolName
            };
            var createdSchool = await schoolRepository.CreateSchool(newSchool);

            await eventSender.SendAsync("SchoolCreated", createdSchool);

            return(createdSchool);
        }