public void T4_trains_are_created_by_companies_and_have_a_unique_name()
        {
            ICity    s = CityFactory.CreateCity("Paris");
            ICompany c = s.AddCompany("SNCF");

            Action a = () => c.AddTrain(null);

            a.ShouldThrow <ArgumentException>();


            ITrain p1 = c.AddTrain("train1");

            p1.Company.Should().BeSameAs(c);
            p1.Name.Should().BeEquivalentTo("train1");
            p1.Assignment.Should().BeNull();
            Action a1 = () => c.AddTrain("train1");

            a1.ShouldThrow <ArgumentException>();


            ITrain p2 = c.AddTrain("train2");

            p2.Company.Should().BeSameAs(c);
            p2.Name.Should().BeEquivalentTo("train2");
            p2.Assignment.Should().BeNull();
            Action a2 = () => c.AddTrain("train2");

            a2.ShouldThrow <ArgumentException>();

            p1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Train.Name must NOT be writeable.");
            p1.GetType().GetProperty("Assignment").GetSetMethod().Should().BeNull("Train.Assignment must NOT be writeable.");
            p1.GetType().GetProperty("City").GetSetMethod().Should().BeNull("Train.City must NOT be writeable.");
            p1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Train must not expose any public constructors.");
        }
        public void T4_trains_can_be_found_by_name()
        {
            ICity s = CityFactory.CreateCity("Paris");

            ICompany c1 = s.AddCompany("Transports de Lyon");
            ICompany c2 = s.AddCompany("Transports de Marseille");

            ITrain t1 = c1.AddTrain("RER1");

            c1.FindTrain("RER1").Should().BeSameAs(t1);
            c2.FindTrain("RER1").Should().BeNull();


            ITrain t2 = c2.AddTrain("RER1");

            c2.FindTrain("RER1").Should().BeSameAs(t2);
            c1.FindTrain("RER1").Should().NotBeSameAs(t2);


            ITrain t3 = c1.AddTrain("RER2");
            ITrain t4 = c1.AddTrain("RER3");
            ITrain t5 = c1.AddTrain("RER4");

            c1.FindTrain("RER2").Should().BeSameAs(t3);
            c1.FindTrain("RER3").Should().BeSameAs(t4);
            c1.FindTrain("RER4").Should().BeSameAs(t5);

            c2.FindTrain("RER2").Should().BeNull();
            c2.FindTrain("RER3").Should().BeNull();
            c2.FindTrain("RER4").Should().BeNull();
        }
        public async Task AddActivityInBucketList()
        {
            //Arrange
            var        activityType = ActivityTypeFactory.Default();
            var        city         = CityFactory.Default();
            var        activity     = ActivityFactory.Default(city.Id, activityType.Id);
            BucketList bucket       = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();

                bucket = await doFestContext
                         .BucketLists
                         .FirstOrDefaultAsync(x => x.UserId == AuthenticatedUserId);
            });

            //Act
            var response = await HttpClient.PostAsync($"/api/v1/bucketlists/{bucket.Id}/activities/{activity.Id}", null);

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
        }
        public async Task DeleteActivity()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var city         = CityFactory.Default();
            var activity     = new Activity(activityType.Id, city.Id, "test name", "test description", "test address");

            //Act
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.SaveChangesAsync();
            });

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
            });

            var response = await HttpClient.DeleteAsync($"/api/v1/activities/{activity.Id}");

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
        }
Beispiel #5
0
        private void Subscribe_Btn(object sender, RoutedEventArgs e)
        {
            if (AreUserFieldsOk())
            {
                string   login        = Login_TxtBox.Text;
                string   password     = Password_Box.Password;
                DateTime birthday     = (DateTime)Birthday_DatePicker.SelectedDate;
                short    streetNumber = Convert.ToInt16(StreetNumber_TxtBox.Text);
                string   streetName   = StreetName_TxtBox.Text;
                string   cityName     = CityName_TxtBox.Text;
                string   postalCode   = PostalCode_TxtBox.Text;
                Region   region       = (Region)Region_cmbBox.SelectedItem;

                City    city              = CityFactory.Get(cityName, postalCode, region);
                Address address           = AddressFactory.Get(streetNumber, streetName, city);
                string  encryptedPassword = Password.Encrypt(password.ToString());

                if (!User.IsInDb(login, encryptedPassword))
                {
                    User user = UserFactory.Create(login, encryptedPassword, birthday, address);
                    DialogBox.Ok("Success", "User has been correctly recorded");
                    ResetInscription();
                }
                else
                {
                    DialogBox.Ok("Error", "Check fields");
                }
            }
            else
            {
                DialogBox.Ok("Error", "Check fields");
            }
        }
        public async Task AddNewActivity()
        {
            //Arrange
            var activityType = ActivityTypeFactory.Default();
            var city         = CityFactory.Default();

            var activity = new CreateActivityModel()
            {
                ActivityTypeId = activityType.Id,
                Address        = "test address",
                CityId         = city.Id,
                Description    = "test description",
                Name           = "test name"
            };

            //Act
            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.SaveChangesAsync();
            });

            //Assert
            var response = await HttpClient.PostAsJsonAsync($"/api/v1/activities", activity);

            response.IsSuccessStatusCode.Should().BeTrue();
        }
        public void T3_stations_can_be_found_by_name()
        {
            ICity s = CityFactory.CreateCity("Paris");

            IStation c1 = s.AddStation("Opera", 0, 0);

            s.FindStation("Opera").Should().BeSameAs(c1);
            s.FindStation("Chatelet").Should().BeNull();


            IStation c2 = s.AddStation("Chatelet", 1, 1);

            s.FindStation("Opera").Should().BeSameAs(c1);
            s.FindStation("Chatelet").Should().BeSameAs(c2);
            s.FindStation("Ivry").Should().BeNull();

            IStation c3 = s.AddStation("Ivry", 2, 2);
            IStation c4 = s.AddStation("Villejuif", 3, 3);
            IStation c5 = s.AddStation("Bourse", 4, 4);

            s.FindStation("Opera").Should().BeSameAs(c1);
            s.FindStation("Chatelet").Should().BeSameAs(c2);
            s.FindStation("Ivry").Should().BeSameAs(c3);
            s.FindStation("Villejuif").Should().BeSameAs(c4);
            s.FindStation("Bourse").Should().BeSameAs(c5);
        }
        public void T1_companies_can_be_found_by_name()
        {
            ICity    s  = CityFactory.CreateCity("Paris");
            ICompany c1 = s.AddCompany("SNCF");

            s.FindCompany("SNCF").Should().BeSameAs(c1);
            s.FindCompany("RATP").Should().BeNull();

            ICompany c2 = s.AddCompany("RATP");

            s.FindCompany("SNCF").Should().BeSameAs(c1);
            s.FindCompany("RATP").Should().BeSameAs(c2);
            s.FindCompany("Transports de Lyon").Should().BeNull();


            ICompany c3 = s.AddCompany("Transports de Lyon");
            ICompany c4 = s.AddCompany("Transports de Marseille");
            ICompany c5 = s.AddCompany("Transports de Lille");

            s.FindCompany("SNCF").Should().BeSameAs(c1);
            s.FindCompany("RATP").Should().BeSameAs(c2);
            s.FindCompany("Transports de Lyon").Should().BeSameAs(c3);
            s.FindCompany("Transports de Marseille").Should().BeSameAs(c4);
            s.FindCompany("Transports de Lille").Should().BeSameAs(c5);


            var randomNames = Enumerable.Range(0, 20).Select(i => String.Format("n°{0} - {1}", i, Guid.NewGuid().ToString())).ToArray();
            var teachers    = randomNames.Select(n => s.AddCompany(n)).ToArray();

            teachers.Should().BeEquivalentTo(randomNames.Select(n => s.FindCompany(n)));
        }
        public void T2_lines_can_be_found_by_name()
        {
            ICity c = CityFactory.CreateCity("Paris");

            ILine l1 = c.AddLine("1");

            c.FindLine("1").Should().BeSameAs(l1);
            c.FindLine("2").Should().BeNull();


            ILine l2 = c.AddLine("2");

            c.FindLine("1").Should().BeSameAs(l1);
            c.FindLine("2").Should().BeSameAs(l2);
            c.FindLine("3").Should().BeNull();


            ILine l3 = c.AddLine("3");
            ILine l4 = c.AddLine("4");
            ILine l5 = c.AddLine("5");

            c.FindLine("1").Should().BeSameAs(l1);
            c.FindLine("2").Should().BeSameAs(l2);
            c.FindLine("3").Should().BeSameAs(l3);
            c.FindLine("4").Should().BeSameAs(l4);
            c.FindLine("5").Should().BeSameAs(l5);


            var randomNames = Enumerable.Range(0, 20)
                              .Select(i => String.Format("n°{0} - {1}", i, Guid.NewGuid().ToString()))
                              .ToArray();
            var lines = randomNames.Select(n => c.AddLine(n)).ToArray();

            lines.Should().BeEquivalentTo(randomNames.Select(n => c.FindLine(n)));
        }
Beispiel #10
0
        static void chooseFactory(int id)
        {
            int level = judgeLevel(id);

            if (level == 1) //省级公司
            {
                IFactory      cpyFactory    = new ProvinceFactory();
                CreateCompany createCompany = cpyFactory.createcompany();
                createCompany.CompanyID    = id;
                createCompany.CompanyName  = CompanyName;
                createCompany.Childcompany = DBhelper.GetChildcompany(id);
                createCompany.createword();
            }
            else if (level == 2) //市级公司
            {
                IFactory      cpyFactory    = new CityFactory();
                CreateCompany createCompany = cpyFactory.createcompany();
                createCompany.CompanyID    = id;
                createCompany.CompanyName  = CompanyName;
                createCompany.Childcompany = DBhelper.GetChildcompany(id);
                createCompany.createword();
            }
            else if (level == 3) //县级公司
            {
                IFactory      cpyFactory    = new CountryFactory();
                CreateCompany createCompany = cpyFactory.createcompany();
                createCompany.CompanyID    = id;
                createCompany.CompanyName  = CompanyName;
                createCompany.Childcompany = DBhelper.GetChildcompany(id);
                createCompany.createword();
            }
        }
        public void T3_lines_are_created_by_cities_and_have_a_unique_name()
        {
            ICity s = CityFactory.CreateCity("Paris");

            Action a = () => s.AddLine(null);

            a.ShouldThrow <ArgumentException>();
            Action ab = () => s.AddLine(String.Empty);

            ab.ShouldThrow <ArgumentException>();


            ILine c1 = s.AddLine("RER A");

            c1.City.Should().BeSameAs(s);
            c1.Name.Should().BeEquivalentTo("RER A");
            Action a1 = () => s.AddLine("RER A");

            a1.ShouldThrow <ArgumentException>();


            ILine c2 = s.AddLine("RER B");

            c2.City.Should().BeSameAs(s);
            c2.Name.Should().BeEquivalentTo("RER B");
            Action a2 = () => s.AddLine("RER B");

            a2.ShouldThrow <ArgumentException>();

            c1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Line.Name must NOT be writeable.");
            c1.GetType().GetProperty("City").GetSetMethod().Should().BeNull("Line.City must NOT be writeable.");
            c1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Line must not expose any public constructors.");
        }
Beispiel #12
0
        private void Add_element_from_create_page()
        {
            //Arrange
            this._model = CityFactory.GetCity(CityType.Paris);

            // Act
            this._controller.Create(this._model);
        }
        private static ICity CreateTestCity()
        {
            ICity    city    = CityFactory.CreateCity("Paris");
            ICompany company = city.AddCompany("ITICORP");
            ITrain   train   = company.AddTrain("TGV");

            return(city);
        }
Beispiel #14
0
 public static CityFactory getInstance()
 {
     if (null == single)
     {
         single = new CityFactory();
     }
     return(single);
 }
Beispiel #15
0
        private void Edit_added_element()
        {
            //Arrange

            // Act
            this._model.Name = CityFactory.GetCity(CityType.NewYork).Name;
            this._controller.Edit(this._model);
        }
        public void T6_line_with_no_stations_doesnt_throw()
        {
            ICity s = CityFactory.CreateCity("Paris");

            ILine  p1 = s.AddLine("K");
            Action a  = () => p1.Stations.Count();

            a.ShouldNotThrow();
        }
        public void ReturnInstanceOfCity()
        {
            var name = "Name";

            var sut  = new CityFactory();
            var city = sut.Create(name);

            Assert.IsInstanceOfType(city, typeof(City));
            Assert.AreEqual(name, city.Name);
        }
        private static ICity CreateTestCity()
        {
            ICity    city = CityFactory.CreateCity("First City");
            ICompany c1   = city.AddCompany("C01");
            ITrain   t1   = c1.AddTrain("T01");
            ICompany c2   = city.AddCompany("C02");
            ITrain   t2   = c2.AddTrain("T02");

            return(city);
        }
Beispiel #19
0
        public void T1_stations_can_be_assigned_to_a_line()
        {
            ICity c  = CityFactory.CreateCity("Paris");
            ILine l1 = c.AddLine("RER A");

            IStation s1 = c.AddStation("Opera", 0, 0);
            IStation s2 = c.AddStation("Chatelet", 1, 1);

            l1.Stations.Count().Should().Be(0);
            s1.Lines.Count().Should().Be(0);
            s2.Lines.Count().Should().Be(0);

            Action a1 = () => l1.AddBefore(null, null);

            a1.ShouldThrow <ArgumentException>();

            Action a2 = () => l1.AddBefore(s1, null);

            a2.ShouldNotThrow();

            l1.Next(s1).Should().BeNull();
            l1.Previous(s1).Should().BeNull();

            s1.Lines.Count().Should().Be(1);

            s1.Lines.Count().Should().Be(1);
            s2.Lines.Count().Should().Be(0);
            s1.Lines.Single().Should().BeSameAs(l1);

            Action a3 = () => l1.Next(s2);

            a3.ShouldThrow <ArgumentException>();

            Action a4 = () => l1.Previous(s2);

            a4.ShouldThrow <ArgumentException>();

            l1.Stations.Single().Should().BeSameAs(s1);

            Action a5 = () => l1.AddBefore(s2, s1);

            a5.ShouldNotThrow();

            l1.Stations.Count().Should().Be(2);

            s1.Lines.Count().Should().Be(1);
            s2.Lines.Count().Should().Be(1);

            l1.Next(s2).Should().BeSameAs(s1);
            l1.Previous(s1).Should().BeSameAs(s2);
            l1.Next(s1).Should().BeNull();
            l1.Previous(s2).Should().BeNull();
            s1.Lines.Single().Should().BeSameAs(l1);
            s2.Lines.Single().Should().BeSameAs(l1);
        }
Beispiel #20
0
        public void T3_stations_cant_be_2_times_on_a_line()
        {
            ICity    c = CityFactory.CreateCity("Paris");
            ILine    l = c.AddLine("RER B");
            IStation s = c.AddStation("Opera", 0, 0);

            l.AddBefore(s);

            Action a1 = () => l.AddBefore(s);

            a1.ShouldThrow <ArgumentException>();
        }
Beispiel #21
0
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //::  Function to extract the useful information from the newly     :::
    //::  generated XML format. The only important information is the   :::
    //::  name of the destination and the lat / lon coordinates         :::
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    private void getUsefulInformation(XElement xmlData)
    {
        IEnumerable <XElement> elements =
            from el in xmlData.Elements()
            select el;

        foreach (XElement el in elements)
        {
            cFac = new CityFactory(el);
            cityNodes.Add(cFac);
        }
    }
Beispiel #22
0
        private void Check_details_of_the_edited_city()
        {
            //Arrange

            // Act
            ViewResult result      = this._controller.Details(this._model.Id) as ViewResult;
            var        detailsCity = result.Model as City;

            // Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(detailsCity);
            Assert.AreEqual(detailsCity.Name, CityFactory.GetCity(CityType.NewYork).Name);
            Assert.AreEqual(detailsCity.Location.Description, this._model.Location.Description);
            Assert.AreEqual("Details", result.ViewName);
        }
Beispiel #23
0
        public static City Get(string cityName, string postalCode, Region region)
        {
            City city;

            if (City.IsInDb(cityName, postalCode))
            {
                city = CityLoader.Load(cityName, postalCode);
            }
            else
            {
                city = CityFactory.Create(region);
                city.RecordInDb();
            }
            return(city);
        }
Beispiel #24
0
        public void Should_Get_Two_Cities()
        {
            using (var session = this._cityUnit.GetSession())
            {
                var citiesRepo  = session.GetRepository();
                var citiesCount = citiesRepo.GetAll().Count();
                var paris       = CityFactory.GetCity(CityType.Paris);
                var newYork     = CityFactory.GetCity(CityType.NewYork);


                citiesRepo.AddRange(new[] { newYork, paris });
                session.Complete();

                Assert.AreEqual(citiesCount + 2, citiesRepo.GetAll().Count());
            }
        }
Beispiel #25
0
        public void T2_when_a_train_is_assigned_to_a_line_he_losts_its_previous_line()
        {
            ICity    s  = CityFactory.CreateCity("Paris");
            ICompany c  = s.AddCompany("SNCF");
            ILine    l1 = s.AddLine("RER A");
            ILine    l2 = s.AddLine("RER B");
            ITrain   t1 = c.AddTrain("RER1");

            t1.AssignTo(l1);

            t1.Assignment.Should().BeSameAs(l1);

            t1.AssignTo(l2);
            t1.Assignment.Should().BeSameAs(l2);
            l1.Trains.Count().Should().Be(0);
            l2.Trains.Single().Should().BeSameAs(t1);
        }
Beispiel #26
0
        public void T5_line_can_have_mutiple_trains()
        {
            ICity    s1 = CityFactory.CreateCity("Paris");
            ICompany c1 = s1.AddCompany("SNCF");
            ILine    l1 = s1.AddLine("RER A");
            ITrain   t1 = c1.AddTrain("RER1");
            ITrain   t2 = c1.AddTrain("RER2");

            t1.AssignTo(l1);
            t2.AssignTo(l1);
            l1.Trains.Count().Should().Be(2);
            l1.Trains.Contains(t1).Should().BeTrue();
            l1.Trains.Contains(t2).Should().BeTrue();

            t1.AssignTo(null);
            l1.Trains.Single().Should().BeSameAs(t2);
        }
        public void T5_stations_are_created_by_cities_and_have_a_unique_name()
        {
            ICity    s  = CityFactory.CreateCity("Paris");
            IStation p1 = s.AddStation("Opera", 0, 0);

            p1.City.Should().BeSameAs(s);
            p1.Name.Should().BeEquivalentTo("Opera");
            p1.X.Should().Be(0);
            p1.Y.Should().Be(0);
            Action a = () => s.AddStation("Opera", 0, 0);

            a.ShouldThrow <ArgumentException>();
            Action a1 = () => s.AddStation("Opera", 10, 0);

            a1.ShouldThrow <ArgumentException>();
            Action a2 = () => s.AddStation("Opera", 0, 10);

            a2.ShouldThrow <ArgumentException>();


            IStation p2 = s.AddStation("Chatelet", 1, 1);

            p2.City.Should().BeSameAs(s);
            p2.Name.Should().BeEquivalentTo("Chatelet");
            p2.X.Should().Be(1);
            p2.Y.Should().Be(1);
            Action a4 = () => s.AddStation("Chatelet", 0, 0);

            a4.ShouldThrow <ArgumentException>();
            Action a5 = () => s.AddStation("Chatelet", 10, 0);

            a5.ShouldThrow <ArgumentException>();
            Action a6 = () => s.AddStation("Chatelet", 0, 10);

            a6.ShouldThrow <ArgumentException>();

            Action a7 = () => s.AddStation("Same Place Station", 0, 0);

            a7.ShouldThrow <ArgumentException>();

            p1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Lane.Name must NOT be writeable.");
            p1.GetType().GetProperty("X").GetSetMethod().Should().BeNull("Lane.X must NOT be writeable.");
            p1.GetType().GetProperty("Y").GetSetMethod().Should().BeNull("Lane.Y must NOT be writeable.");
            p1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Train must not expose any public constructors.");
        }
Beispiel #28
0
        public void T4_assigning_a_train_to_a_null_line_removes_its_assignment()
        {
            ICity    s1 = CityFactory.CreateCity("Paris");
            ICompany c1 = s1.AddCompany("SNCF");
            ILine    l1 = s1.AddLine("RER A");
            ITrain   t1 = c1.AddTrain("RER1");

            Action a1 = () => t1.AssignTo(null);

            a1.ShouldNotThrow();

            t1.AssignTo(l1);
            t1.Assignment.Should().BeSameAs(l1);

            t1.AssignTo(null);
            t1.Assignment.Should().BeNull();
            l1.Trains.Count().Should().Be(0);
        }
Beispiel #29
0
        public void T3_trains_and_lines_must_belong_to_the_same_city()
        {
            ICity    s1 = CityFactory.CreateCity("Paris");
            ICompany c1 = s1.AddCompany("SNCF");
            ILine    l1 = s1.AddLine("RER A");
            ITrain   t1 = c1.AddTrain("RER1");

            ICity    s2 = CityFactory.CreateCity("Lyon");
            ICompany c2 = s2.AddCompany("SNCF");
            ILine    l2 = s2.AddLine("RER A");
            ITrain   t2 = c2.AddTrain("RER1");

            Action a1 = () => t1.AssignTo(l1);
            Action a2 = () => t1.AssignTo(l2);

            a1.ShouldNotThrow();
            a2.ShouldThrow <ArgumentException>();
        }
        public async Task UpdateBucketList()
        {
            //Arrange
            var        activityType = ActivityTypeFactory.Default();
            var        city         = CityFactory.Default();
            var        activity     = ActivityFactory.Default(city.Id, activityType.Id);
            BucketList bucket       = null;
            var        updateModel  = new BucketListUpdateModel()
            {
                Name = "bucketlist test",
                ActivitiesForDelete = new List <Guid>(),
                ActivitiesForToggle = new List <Guid>()
            };

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                bucket = await doFestContext
                         .BucketLists
                         .FirstOrDefaultAsync(x => x.UserId == AuthenticatedUserId);
                await doFestContext.Cities.AddAsync(city);
                await doFestContext.ActivityTypes.AddAsync(activityType);
                await doFestContext.Activities.AddAsync(activity);
                await doFestContext.SaveChangesAsync();
                await doFestContext.BucketListActivities.AddAsync(new BucketListActivity(bucket.Id, activity.Id));
                await doFestContext.SaveChangesAsync();
            });

            //Act
            var response = await HttpClient.PutAsJsonAsync($"/api/v1/bucketlists/{bucket.Id}/activities", updateModel);

            //Assert
            response.IsSuccessStatusCode.Should().BeTrue();
            BucketList existingBucketList = null;

            await ExecuteDatabaseAction(async (doFestContext) =>
            {
                existingBucketList = await doFestContext
                                     .BucketLists
                                     .FirstOrDefaultAsync(x => x.UserId == AuthenticatedUserId);
            });

            existingBucketList.Should().NotBeNull();
            existingBucketList.Name.Should().Be(updateModel.Name);
        }
Beispiel #31
0
        public IGame BuildGame()
        {
            // This composition of the game using poor man's DI does not support automatic registration.
            // To give a fairer view in the benchmark, it invokes the reflection used for automatic registration,
            // though it discards the results.
            var cityTypes = TypeConstraints.Cities;
            var cityFactoryTypes = TypeConstraints.CityFactories;
            var terrainTypes = TypeConstraints.Terrains;
            var terrainFactoryTypes = TypeConstraints.TerrainFactories;
            var unitTypes = TypeConstraints.Units;
            var unitFactoryTypes = TypeConstraints.UnitFactories;
            var productionProjectTypes = TypeConstraints.ProductionProjects;

            // :::: TURN-TAKING ::::
            var players = new[] { new Player("Red"), new Player("Blue") };
            var turnTaking = new RoundRobinTurns(players);

            // :::: UNIT COMBAT ::::
            var unitCombat = new AttackerIsAlwaysVictorious();

            // :::: WORLD MAP COLLECTIONS ::::
            var cities = new HashSet<ICity>(new CityEqualityComparer());
            var terrains = new HashSet<ITerrain>(new TerrainEqualityComparer());
            var units = new HashSet<IUnit>(new UnitEqualityComparer());

            // :::: CITIES ::::
            var cityFactory = new CityFactory(
                () => new FriendlyCityManagementOnly<City>(
                          new ProductionAccumulation<City>(
                              new FixedGeneratedProduction<City>(
                                  new NoCityGrowth<City>(new City())
                                  ), units, turnTaking
                              ), turnTaking
                          ));

            // :::: TERRAINS ::::
            var forestsFactory = new ForestsFactory(() => new Forests());
            var hillsFactory = new HillsFactory(() => new Hills());
            var mountainsFactory = new MountainsFactory(() => new Mountains());
            var oceansFactory = new OceansFactory(() => new Oceans());
            var plainsFactory = new PlainsFactory(() => new Plains());

            // :::: UNITS ::::
            var archerFactory = new ArcherFactory(
                () => new FriendlyUnitManagementOnly<Archer>(
                          new FortificationAction<Archer>(
                              new NoEntranceToImpassableTerrain<Archer>(
                                  new NoFriendlyUnitStacking<Archer>(
                                      new LimitedMoveRange<Archer>(
                                          new OneToOneCombatEngagement<Archer>(
                                              new CityConquest<Archer>(
                                                  new RestorationOfMoves<Archer>(
                                                      new MoveCosts<Archer>(
                                                          new Movability<Archer>(new Archer())
                                                          ), turnTaking
                                                      ), cities
                                                  ), units, unitCombat
                                              )
                                          ), units
                                      ), terrains
                                  )
                              ), turnTaking
                          ));

            var chariotFactory = new ChariotFactory(
                () => new FriendlyUnitManagementOnly<Chariot>(
                          new FortificationAction<Chariot>(
                              new NoEntranceToImpassableTerrain<Chariot>(
                                  new NoFriendlyUnitStacking<Chariot>(
                                      new LimitedMoveRange<Chariot>(
                                          new OneToOneCombatEngagement<Chariot>(
                                              new CityConquest<Chariot>(
                                                  new RestorationOfMoves<Chariot>(
                                                      new MoveCosts<Chariot>(
                                                          new Movability<Chariot>(new Chariot())
                                                          ), turnTaking
                                                      ), cities
                                                  ), units, unitCombat
                                              )
                                          ), units
                                      ), terrains
                                  )
                              ), turnTaking
                          ));

            var legionFactory = new LegionFactory(
                () => new FriendlyUnitManagementOnly<Legion>(
                          new NoEntranceToImpassableTerrain<Legion>(
                              new NoFriendlyUnitStacking<Legion>(
                                  new LimitedMoveRange<Legion>(
                                      new OneToOneCombatEngagement<Legion>(
                                          new CityConquest<Legion>(
                                              new RestorationOfMoves<Legion>(
                                                  new MoveCosts<Legion>(
                                                      new Movability<Legion>(new Legion())
                                                      ), turnTaking
                                                  ), cities
                                              ), units, unitCombat
                                          )
                                      ), units
                                  ), terrains
                              ), turnTaking
                          ));

            var settlerFactory = new SettlerFactory(
                () => new FriendlyUnitManagementOnly<Settler>(
                          new CityBuildingAction<Settler>(
                              new NoEntranceToImpassableTerrain<Settler>(
                                  new NoFriendlyUnitStacking<Settler>(
                                      new LimitedMoveRange<Settler>(
                                          new OneToOneCombatEngagement<Settler>(
                                              new RestorationOfMoves<Settler>(
                                                  new MoveCosts<Settler>(
                                                      new Movability<Settler>(new Settler())
                                                      ), turnTaking
                                                  ), units, unitCombat
                                              )
                                          ), units
                                      ), terrains
                                  ), units, cities, cityFactory
                              ), turnTaking
                          ));

            // :::: WORLD MAP LAYERS ::::
            var cityLayer = new SimpleFixedCityLayer(cities, cityFactory);

            var terrainLayer = new SimpleFixedTerrainLayer(terrains,
                                                           hillsFactory,
                                                           mountainsFactory,
                                                           oceansFactory,
                                                           plainsFactory);

            var unitLayer = new SimpleFixedUnitLayer(units, archerFactory, legionFactory, settlerFactory);

            // :::: WORLD AGE ::::
            var worldAge = new DeceleratingWorldAge(turnTaking);

            // :::: WINNER STRATEGY ::::
            var winnerStrategy = new CityConquerorWins(cities);

            // :::: PRODUCTION PROJECTS ::::
            var productionProjects = new Dictionary<string, IProductionProject>
            {
                ["Archer"] = new ArcherProject(archerFactory),
                ["Chariot"] = new ChariotProject(chariotFactory),
                ["Legion"] = new LegionProject(legionFactory),
                ["Settler"] = new SettlerProject(settlerFactory),
            };

            // :::: GAME ::::
            var game = new ExtenCivGame(cityLayer, terrainLayer, unitLayer,
                                        turnTaking, worldAge, winnerStrategy, productionProjects)
            {
                ContainerName = "Manual/SemiCiv"
            };

            return game;
        }