Ejemplo n.º 1
0
        public void Country_Aggregate_With_CapitalCity_Tests()
        {
            // Insert
            var insertCountryAggregate = new InsertCountryWithCapitalCityCommandAggregate(new CountryWithCapitalCityDto
            {
                CountryCode = "us",
                Name        = "United States",
                CapitalCity = new CapitalCityDto
                {
                    Name = "Washington"
                }
            });

            insertCountryAggregate.Save();

            var countryEntity = insertCountryAggregate.RootEntity;

            Assert.AreEqual("us", countryEntity.Id);

            var capitalCity = insertCountryAggregate.CapitalCity;

            Assert.AreEqual(1, capitalCity.Id);

            Assert.AreEqual("Washington", capitalCity.Name);

            Assert.AreEqual("us", capitalCity.CountryCode);

            // Read
            var queryAggregate = new CountryCapitalCityQueryAggregate();

            queryAggregate.Get("us");

            countryEntity = queryAggregate.RootEntity;

            Assert.AreEqual("us", countryEntity.Id);

            Assert.AreEqual("United States", countryEntity.Name);

            capitalCity = queryAggregate.CapitalCity;

            Assert.AreEqual(1, capitalCity.Id);

            Assert.AreEqual("Washington", capitalCity.Name);

            Assert.AreEqual("us", capitalCity.CountryCode);

            // Delete
            var deleteAggregate = new DeleteCountryCapitalCityCommandAggregate("us");

            deleteAggregate.Save();

            queryAggregate.Get("us");

            Assert.IsNull(queryAggregate.RootEntity);
        }
Ejemplo n.º 2
0
        public void Country_Aggregate_With_CapitalCity_Country_Only_Tests()
        {
            // Insert
            var insertCountryAggregate = new InsertCountryWithCapitalCityCommandAggregate(
                new CountryWithCapitalCityDto
            {
                CountryCode = "il",
                Name        = "ISRAEL",
                CapitalCity = null
            });

            insertCountryAggregate.Save();

            var countryEntity = insertCountryAggregate.RootEntity;

            Assert.AreEqual("ISRAEL", countryEntity.Name);

            Assert.AreEqual("il", countryEntity.Id);

            // Read

            var queryAggregate = new CountryCapitalCityQueryAggregate();

            queryAggregate.Get("il", null);

            countryEntity = queryAggregate.RootEntity;

            Assert.AreEqual("il", countryEntity.Id);

            Assert.AreEqual("ISRAEL", countryEntity.Name);

            // Update
            var updateCountryAggregate = new UpdateCountryCommandAggregate(
                new CountryWithCapitalCityDto
            {
                CountryCode = "il",
                Name        = "Israel",
                CapitalCity = null
            });

            updateCountryAggregate.Save();

            // Read after update

            queryAggregate.Get("il");

            countryEntity = queryAggregate.RootEntity;

            Assert.AreEqual("il", countryEntity.Id);

            Assert.AreEqual("Israel", countryEntity.Name);

            // Delete

            var context = new RepositoryContext(connectionName);

            context.RegisterCommandRepositoryFactory <CountryEntity>(() => new CountryCommandRepository());

            var deleteAggregate = new DeleteCountryCapitalCityCommandAggregate("il");

            deleteAggregate.Save();

            queryAggregate.Get("il");

            Assert.IsNull(queryAggregate.RootEntity);
        }