public void AddVehicle()
        {
            //Arrange
            var vehicles = new Vehicles();
            var plane = new Plane { Name = "Boeing 747" };
            var car = new Car { Name = "Prius", ManufacturerID = 999 };

            //Act
            vehicles.Add(plane);
            vehicles.Add(car);

            //Assert
            Assert.AreEqual(vehicles.Count, 1);
        }
        public void ParseFileName(string path)
        {
            var filename = Path.GetFileNameWithoutExtension(path);

            if (ReplayList.IsLeftDate || ReplayList.IsRightDate)
            {
                var date = File.GetLastWriteTime(path).Date;
                if (ReplayList.IsLeftDate && date < ReplayList.LeftDate)
                {
                    throw new NotImplementedException();
                }
                if (ReplayList.IsRightDate && date > ReplayList.RightDate)
                {
                    throw new NotImplementedException();
                }
            }
            var tw      = filename.Split(chararray, StringSplitOptions.RemoveEmptyEntries);
            var mapindx = Array.FindLastIndex(tw, x => x.All(y => char.IsDigit(y)));

            Tank = new ArraySegment <string>(tw, 2, mapindx - 2).JoinIntoString("_");
            Map  = TryReplaceMap(new ArraySegment <string>(tw, mapindx, tw.Length - mapindx).JoinIntoString("_").Replace('-', ' ').Replace('_', '-'));
            var json = string.Empty;

            using (var stream = File.OpenRead(path))
            {
                using (var br = new BinaryReader(stream))
                {
                    br.BaseStream.Position = 4;
                    var jsonscount  = br.ReadInt32();
                    var jsonbuilder = new StringBuilder();
                    for (var i = 0; i < jsonscount; i++)
                    {
                        jsonbuilder.Append(ANSI.GetString(br.ReadBytes(br.ReadInt32())));
                    }
                    json = jsonbuilder.ToString();
                }
            }

            {
                var damageindex = 0;
                do
                {
                    damageindex = json.IndexOf(damageDealt, damageindex + damageDealt.Length);
                    if (damageindex == -1)
                    {
                        Damage = -1;
                        break;
                    }
                    var damagestr = GetNextString(12, json, damageDealt, damageindex);
                    if (damagestr.Contains("}"))
                    {
                        continue;
                    }
                    if (damagestr == null)
                    {
                        Damage = -1;
                    }
                    else
                    {
                        Damage = int.Parse(damagestr.Replace("\"", ""));
                    }
                    break;
                }while (damageindex != -1);
            }

            {
                var gameplayidstr = GetNextString(24, json, gameplayID);
                var battletypestr = GetNextString(20, json, battleType);
                if (gameplayidstr == null || battletypestr == null)
                {
                    gameplayidstr = GetNextString(24, json, gameplayID2);
                    battletypestr = GetNextString(20, json, battleType2);
                }
                OrigMode = $"{gameplayidstr.Replace("\"", "")}_{battletypestr}";
                Mode     = TryReplaceMode(OrigMode);
            }

            var owntankcount = 0;

            var indx     = 0;
            var count    = 0;
            var maxcount = GetMaximumVehicles(OrigMode);

            do
            {
                indx = json.IndexOf(vehicleType, indx + vehicleType.Length);
                if (indx == -1)
                {
                    break;
                }
                var tankstr = GetNextString(48, json, vehicleType, indx);
                if (tankstr == null)
                {
                    tankstr = GetNextString(48, json, vehicleType2, indx);
                }
                var tankname = ParseTankNameFronJSON(tankstr).Replace("\"", "");
                if (Tank == tankname)
                {
                    owntankcount++;
                    if (owntankcount > 1)
                    {
                        Vehicles.Add(tankname);
                    }
                }
                else
                {
                    Vehicles.Add(tankname);
                }
                count++;
            }while (indx != -1 && count < maxcount);
            Artys = Vehicles.Count(x => ArtysNames.Contains(x));
        }
Exemple #3
0
        public void Seed(ILogger <AppDbContext> logger, string scriptsPath)
        {
            if (Companies.Any())
            {
                return;
            }

            var  scripts        = new string [] { Path.Combine(scriptsPath, "countys.sql"), Path.Combine(scriptsPath, "citys.sql"), Path.Combine(scriptsPath, "districts.sql") };
            bool allFilesExists = scripts.Select(x => File.Exists(x) ? 0 : 1).Sum() == 0;

            if (allFilesExists)
            {
                using (var transaction = Database.BeginTransaction())
                {
                    foreach (var file in scripts)
                    {
                        var fileContent = System.IO.File.ReadAllLines(Path.Combine(scriptsPath, file));
                        foreach (var statement in fileContent)
                        {
                            this.Database.ExecuteSqlCommand(new RawSqlString(statement));
                        }
                    }

                    transaction.Commit();
                }
            }
            else
            {
                logger.LogCritical("Scripts (Endereços) do banco de dados não encontrados");
            }

            #region Data Test
            using (var transaction = Database.BeginTransaction())
            {
                int companyId = 1;
                int clientId  = 1;
                var unit      = new Repository.UnitWork(new Repository.UnitWorkInfo {
                    CompanyId = companyId
                }, this, null);

                Companies.Add(new CompanyEty
                {
                    Name    = "Company Test",
                    CpfCnpj = "00011122299",
                    Email   = "*****@*****.**",
                    Phone   = "33900112233"
                });
                SaveChanges();

                Users.Add(new UserEty
                {
                    Id        = unit.GenereteId("Users"),
                    CompanyId = companyId,
                    Name      = "User Test",
                    Email     = "*****@*****.**",
                    Password  = "******"
                });
                SaveChanges();

                Clients.Add(new ClientEty
                {
                    Id          = unit.GenereteId("Clients"),
                    CompanyId   = companyId,
                    Name        = "Client Test",
                    Email       = "*****@*****.**",
                    CpfCnpj     = "11122233388",
                    Phone       = "33900886655",
                    ContactName = "C Test",
                    RgIE        = "AA 12120000",
                    Org         = "AA",
                    Address     = new AddressEty
                    {
                        CountyId       = 31,
                        CountyName     = "Minas Gerais",
                        CountyInitials = "MG",
                        CityId         = 3127701,
                        CityName       = "GV",
                        DistrictId     = 0,
                        DistrictName   = "Centro",
                        Number         = "60",
                        Street         = "AV Minas Gerais",
                        ZipCode        = "35060000",
                    }
                });
                SaveChanges();

                Services.Add(new ServiceEty
                {
                    Id        = unit.GenereteId("Services"),
                    CompanyId = companyId,
                    Name      = "Service Test",
                    Rate      = 10,
                    PlateCard = 5,
                    Honorary  = 30,
                    Other     = 1
                });
                SaveChanges();

                Vehicles.Add(new VehicleEty
                {
                    Id              = unit.GenereteId("Vehicles"),
                    CompanyId       = companyId,
                    ClientId        = clientId,
                    Model           = "Model test",
                    Plate           = "AAA0000",
                    Color           = "Red",
                    Chassis         = "CHS 000",
                    Renavam         = "RNV 000",
                    ModelYear       = 2019,
                    YearManufacture = 2019,
                    CountyId        = 31,
                    CountyName      = "Minas Gerais",
                    CountyInitials  = "MG",
                    CityId          = 3127701,
                    CityName        = "Governador Valadares",
                    Type            = VehicleTypeEty.MotorCycle
                });
                SaveChanges();

                transaction.Commit();
            }
            #endregion
        }
Exemple #4
0
        private async Task InitAsync(People person)
        {
            IsLoading = true;

            if (person != null)
            {
                Person = person;

                Species.Clear();
                if (person.species != null && person.species.Count() > 1)
                {
                    foreach (var specy in person.species)
                    {
                        var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                           await _dataService.GetSingleByUrl <Specie>(specy);

                        Species.Add(currentSpecy);
                    }
                    Species = Species.OrderBy(item => item.name).ToObservableCollection();
                }
                else
                {
                    var specy = person.species.FirstOrDefault();
                    if (specy != null)
                    {
                        CurrentSpecie = await _speciesRepository.GetSpecieAsync(specy) ??
                                        await _dataService.GetSingleByUrl <Specie>(specy);
                    }
                }

                Starships.Clear();
                foreach (var starship in person.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in person.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                var movies = new ObservableCollection <Film>();
                foreach (var film in person.films)
                {
                    var currentFilm = await _filmRepository.GetFilmAsync(film) ??
                                      await _dataService.GetSingleByUrl <Film>(film);

                    movies.Add(currentFilm);
                }
                Movies = movies.OrderBy(item => item.episode_id).ToObservableCollection();

                HomeWorld = await _planetRepository.GetPlanetAsync(Person?.homeworld) ??
                            await _dataService.GetSingleByUrl <Planet>(Person?.homeworld);
            }
            IsLoading = false;
        }
 public TestCharacter SetVehicle(Vehicle vehicle)
 {
     Vehicles.Add(vehicle);
     return(this);
 }
Exemple #6
0
 public void Add(Car item)
 {
     Vehicles.Add(item);
 }
Exemple #7
0
        public MemContext()
        {
            var account = new Account
            {
                Id          = 1,
                Name        = "My Test Account",
                Paid        = true,
                PaidUtc     = new DateTime(2016, 1, 1),
                AccountType = AccountType.Gold
            };

            Accounts.Add(account);
            var user = new User
            {
                Id        = 1,
                Name      = "Joe User",
                AccountId = 1,
                Account   = account,
                Active    = true
            };

            Users.Add(user);
            account.Users = new List <User> {
                user
            };
            var account2 = new Account
            {
                Id          = 2,
                Name        = "Another Test Account",
                Paid        = false,
                AccountType = AccountType.Silver
            };

            Accounts.Add(account2);
            var user2 = new User
            {
                Id        = 2,
                Name      = "Late Paying User",
                AccountId = 2,
                Account   = account2
            };

            Users.Add(user2);
            MutateMes.Add(new MutateMe
            {
                Id    = 1,
                Value = 0,
            });
            account2.Users = new List <User> {
                user2
            };

            var human = new Human
            {
                Id     = 1,
                Name   = "Han Solo",
                Height = 5.6430448
            };

            Heros.Add(human);
            var stormtrooper = new Stormtrooper
            {
                Id             = 2,
                Name           = "FN-2187",
                Height         = 4.9,
                Specialization = "Imperial Snowtrooper"
            };

            Heros.Add(stormtrooper);
            var droid = new Droid
            {
                Id              = 3,
                Name            = "R2-D2",
                PrimaryFunction = "Astromech"
            };

            Heros.Add(droid);

            var vehicle = new Vehicle
            {
                Id      = 1,
                Name    = "Millennium falcon",
                OwnerId = human.Id
            };

            Vehicles.Add(vehicle);
            human.Vehicles = new List <Vehicle> {
                vehicle
            };
            var vehicle2 = new Vehicle
            {
                Id      = 2,
                Name    = "Speeder bike",
                OwnerId = stormtrooper.Id
            };

            Vehicles.Add(vehicle2);
            stormtrooper.Vehicles = new List <Vehicle> {
                vehicle2
            };
        }