public void ShouldMakeInstancesCorrectly() { IAssembler assembler = new VehicleAssembler(); Assert.DoesNotThrow(() => new Revenger("Test", 100, 100, 100, 100, 100, assembler)); Assert.DoesNotThrow(() => new Vanguard("Test2", 100, 100, 100, 100, 100, assembler)); }
private void GetVehicles() { try { Vehicles.Clear(); var service = Infrastructure.Container.GetInstance <IVtsWebService>(); if (LoggedUserContext.LoggedUser == null) { return; } foreach (VehicleDto vehicleDto in service.GetVehiclesForUser( LoggedUserContext.LoggedUser.Login, LoggedUserContext.LoggedUser.PasswordHash)) { vehicles.Add(new VehicleViewModel( VehicleAssembler.FromDtoToDomainObject(vehicleDto))); } } catch (Exception e) { const string message = "Can not get vehicles for current user."; Log.Error(e, message); ErrorWindow w = new ErrorWindow(e, message); w.ShowDialog(); } }
public void BaseVehicleTest() { IAssembler assembler = new VehicleAssembler(); IVehicle vanguard = new Vanguard("Vanguard1", 500, 1000, 500, 500, 1000, assembler); IPart arsenalPart = new ArsenalPart("Arsenal1", 100, 100, 100); IPart shellPart = new ShellPart("Shell1", 100, 100, 100); IPart endurancePart = new EndurancePart("Endurance1", 100, 100, 100); vanguard.AddArsenalPart(arsenalPart); vanguard.AddEndurancePart(endurancePart); vanguard.AddShellPart(shellPart); double totalWeight = vanguard.TotalWeight; decimal totalPrice = vanguard.TotalPrice; long totalAttack = vanguard.TotalAttack; long totalDefense = vanguard.TotalDefense; long totalHitPoints = vanguard.TotalHitPoints; Assert.That(totalWeight, Is.EqualTo(800).NoClip); Assert.That(totalPrice, Is.EqualTo(1300).NoClip); Assert.That(totalAttack, Is.EqualTo(600).NoClip); Assert.That(totalDefense, Is.EqualTo(600).NoClip); Assert.That(totalHitPoints, Is.EqualTo(1100).NoClip); string expectedResult = "Vanguard - Vanguard1\r\nTotal Weight: 800.000\r\nTotal Price: 1300.000\r\nAttack: 600\r\nDefense: 600\r\nHitPoints: 1100\r\nParts: Arsenal1, Endurance1, Shell1"; string actualResult = vanguard.ToString(); Assert.That(expectedResult, Is.EqualTo(actualResult).NoClip); }
public void CheckOverrideToString() { string model = "Rhino-CE"; double weight = 12; decimal price = 19; int attack = 80; int defense = 11; int hitPoints = 3; IAssembler assembler = new VehicleAssembler(); BaseVehicle testVehicle = new Revenger(model, weight, price, attack, defense, hitPoints, assembler); IPart arsenalPart = new ArsenalPart("arse1", 1, 1, 2); testVehicle.AddArsenalPart(arsenalPart); IPart shellPart = new ShellPart("hel1", 6, 1, 8); testVehicle.AddShellPart(shellPart); IPart endurancePart = new EndurancePart("end1", 1, 3, 2); testVehicle.AddEndurancePart(endurancePart); string expectedMessage = "Revenger - Rhino-CE\r\nTotal Weight: 20.000\r\nTotal Price: 24.000\r\nAttack: 82\r\nDefense: 19\r\nHitPoints: 5\r\nParts: arse1, hel1, end1"; string actualMessage = testVehicle.ToString(); Assert.AreEqual(expectedMessage, actualMessage); }
private void GetAvailableVehicles() { availableVehiclesForClient.Clear(); if (selectedClient == null) { return; } try { var service = Infrastructure.Container.GetInstance <IVtsWebService>(); foreach (VehicleDto vehicleDto in service.GetVehiclesForUser( selectedClient.Model.Login, selectedClient.Model.PasswordHash)) { availableVehiclesForClient.Add(new VehicleViewModel( VehicleAssembler.FromDtoToDomainObject(vehicleDto))); } } catch (Exception e) { const string msg = "Could not retrieve available vehicles."; Log.Error(e, msg); ErrorWindow w = new ErrorWindow(e, msg); w.Owner = MainWindowKeeper.MainWindowInstance as Window; w.ShowDialog(); } }
public void TestExceptions() { //string model,double weight,decimal price, //int attack,int defense,int hitPoints, IAssembler assembler string model = null; double weight = 22.2; decimal price = 5; int attack = 3; int defense = 4; int hitPoints = 2; IAssembler assembler = new VehicleAssembler(); //checks if model with value null or whitespace throws Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); model = " "; Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); model = "Asd"; //checks if weight <= 0 throws weight = 0; Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); weight = 33.3; //checks if price <= 0 throws price = 0; Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); price = 3; //checks if attack < 0 throws attack = -1; Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); attack = 1; //checks if defense < 0 throws defense = -1; Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); defense = 2; //checks if hitPoints < 0 throws hitPoints = -1; Assert.Throws <ArgumentException>(() => { new Revenger(model, weight, price, attack, defense, hitPoints, assembler); }); }
public ViewResult Index(User currentUser) { List <Vehicle> model = service.GetVehiclesForUser(currentUser.Login, currentUser.PasswordHash). Select(v => VehicleAssembler.FromDtoToDomainObject(v)) .ToList(); return(View(model)); }
public void ToStringShouldReturnProperString() { IAssembler assembler = new VehicleAssembler(); IVehicle vehicle = new Vanguard(model, weight, price, attack, defense, hitPoints, assembler); string result = "Vanguard - bleh\r\nTotal Weight: 30.000\r\nTotal Price: 40.000\r\nAttack: 50\r\nDefense: 60\r\nHitPoints: 70\r\nParts: None"; Assert.That(vehicle.ToString(), Is.EqualTo(result)); }
public IVehicle CreateVehicle(string vehicleType, string model, double weight, decimal price, int attack, int defense, int hitPoints) { var vehicleAssembler = new VehicleAssembler(); var type = Assembly.GetCallingAssembly().GetTypes().FirstOrDefault(t => t.Name == vehicleType); var instance = (IVehicle)Activator.CreateInstance(type, new object[] { model, weight, price, attack, defense, hitPoints, vehicleAssembler }); return(instance); }
public IVehicle CreateVehicle(string vehicleType, string model, double weight, decimal price, int attack, int defense, int hitPoints) { IAssembler assembler = new VehicleAssembler(); Type vType = Assembly.GetCallingAssembly().GetTypes().FirstOrDefault(x => x.Name == vehicleType); IVehicle vehicle = (IVehicle)Activator.CreateInstance(vType, model, weight, price, attack, defense, hitPoints, assembler); return(vehicle); }
public void CheckInvalidExceptions(string model, double weight, decimal price, int attack, int defense, int hitPoints) { IAssembler assembler = new VehicleAssembler(); BaseVehicle testVehicle; Assert.That ( () => testVehicle = new Revenger(model, weight, price, attack, defense, hitPoints, assembler), Throws.ArgumentException ); }
public void DoesPriceThrowExceptionIfValueIsNegativeNumber() { string model = "aaa"; double weight = 1; decimal price = -1; int attack = 1; int defense = 1; int hitpoint = 1; var assembler = new VehicleAssembler(); Assert.Throws(typeof(ArgumentException), () => new Revenger(model, weight, price, attack, defense, hitpoint, assembler)); }
public IVehicle CreateVehicle(string vehicleType, string model, double weight, decimal price, int attack, int defense, int hitPoints) { IAssembler assembler = new VehicleAssembler(model, weight, price, attack, defense, hitPoints); var vehicleTypes = Assembly.GetCallingAssembly().GetTypes() .Where(t => typeof(IVehicle).IsAssignableFrom(t) && !t.IsAbstract) .ToArray(); var carType = vehicleTypes.FirstOrDefault(t => t.Name.Contains(vehicleType)); var vehicle = (IVehicle)Activator.CreateInstance(carType, new object[] { model, weight, price, attack, defense, hitPoints, assembler }); return(vehicle); }
public void AddEndurancePartShouldAddThePartToAssembler() { //Arrange var part = new EndurancePart("part", 10, 10, 10); IAssembler assembler = new VehicleAssembler(); IVehicle vehicle = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); //Action vehicle.AddEndurancePart(part); bool assemblerHasPart = assembler.EnduranceParts.Any(ap => ap.Equals(part)); //Assert Assert.AreEqual(true, assemblerHasPart); }
public void TestBaseVehicleClassReturnsCorrectOutput() { //Vehicle Vanguard SA-203 100 300 1000 450 2000 var assembler = new VehicleAssembler(); var vehicle = new Vanguard("SA-203", 100, 300, 1000, 450, 2000, assembler); var part = new ShellPart("SA-203", 300, 100, 2); vehicle.AddShellPart(part); var actualResult = vehicle.ToString(); var expectedResult = "Vanguard - SA-203\r\nTotal Weight: 400.000\r\nTotal Price: 400.000\r\nAttack: 1000\r\nDefense: 452\r\nHitPoints: 2000\r\nParts: SA-203"; Assert.That(actualResult, Is.EqualTo(expectedResult)); }
public void TotalHitPointsShouldReturnCorrectValue() { var part = new EndurancePart("model", 10, 10, 100); IAssembler assembler = new VehicleAssembler(); assembler.AddEndurancePart(part); IVehicle v = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); var expectedVehicleTotal = v.HitPoints + assembler.TotalHitPointModification; var actualVehicleTotal = v.TotalHitPoints; Assert.AreEqual(expectedVehicleTotal, actualVehicleTotal); }
public void TotalDefenseShouldReturnCorrectValue() { var part = new ShellPart("model", 10, 10, 100); IAssembler assembler = new VehicleAssembler(); assembler.AddShellPart(part); IVehicle v = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); var expectedVehicleTotal = v.Defense + assembler.TotalDefenseModification; var actualVehicleTotal = v.TotalDefense; Assert.AreEqual(expectedVehicleTotal, actualVehicleTotal); }
public void TotalAttackShouldReturnCorrectValue() { var arsenalPart = new ArsenalPart("model", 10, 10, 100); IAssembler assembler = new VehicleAssembler(); assembler.AddArsenalPart(arsenalPart); IVehicle v = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); var expectedVehicleTotal = v.Attack + assembler.TotalAttackModification; var actualVehicleTotal = v.TotalAttack; Assert.AreEqual(expectedVehicleTotal, actualVehicleTotal); }
public IVehicle CreateVehicle(string vehicleType, string model, double weight, decimal price, int attack, int defense, int hitPoints) { Assembly assembly = Assembly.GetCallingAssembly(); Type type = assembly.GetTypes().FirstOrDefault(t => t.Name == vehicleType); IAssembler assembler = new VehicleAssembler(); if (type == null) { throw new InvalidOperationException("Invalid vehicle type!"); } IVehicle part = (IVehicle)Activator.CreateInstance(type, model, weight, price, attack, defense, hitPoints, assembler); return(part); }
public void IsHitPointsEceptionInitialisedCorrectly() { var type = typeof(BaseVehicle); //string model,double weight,decimal price, int attack,int defense,int hitPoints, IAssembler assembler string model = null; double weight = 23; decimal price = 23m; int attack = 23; int defense = 23; int hitPoints = -1; VehicleAssembler assembler = new VehicleAssembler(); Assert.Throws <ArgumentException>(() => new Revenger(model, weight, price, attack, defense, hitPoints, assembler)); }
public void DoesModelThrowExceptionIfValueIsNull() { // string model, double weight, decimal price, int attack, int defense, int hitPoints, IAssembler assembler string model = null; double weight = 1; decimal price = 1; int attack = 1; int defense = 1; int hitpoint = 1; var assembler = new VehicleAssembler(); Assert.Throws(typeof(ArgumentException), () => new Revenger(model, weight, price, attack, defense, hitpoint, assembler)); }
public void CheckIfReturnCorrectResult() { var assembler = new VehicleAssembler(); var tank = new Vanguard("SA - 203", 100, 300, 1000, 450, 2000, assembler); var tank2 = new Revenger("AKU", 1000, 1000, 1000, 1000, 1000, assembler); var part1 = new ArsenalPart("Cannon - KA2", 300, 500, 450); var part2 = new ShellPart("Shields - PI1", 200, 1000, 750); var expectedResult = tank.ToString(); var actualResult = "Vanguard - SA - 203\r\nTotal Weight: 100.000\r\nTotal Price: 300.000\r\nAttack: 1000\r\nDefense: 450\r\nHitPoints: 2000\r\nParts: None"; Assert.AreEqual(expectedResult, actualResult); }
public void TotalPriceShouldReturnCorrectValue() { var arsenalPart = new ArsenalPart("model", 10, 110, 10); IAssembler assembler = new VehicleAssembler(); assembler.AddArsenalPart(arsenalPart); var assemblerTotalPrice = assembler.TotalPrice; IVehicle v = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); var expectedVehicleTotalPrice = v.Price + assemblerTotalPrice; var actualVehicleTotalPrice = v.TotalPrice; Assert.AreEqual(expectedVehicleTotalPrice, actualVehicleTotalPrice); }
public IVehicle CreateVehicle(string vehicleType, string model, double weight, decimal price, int attack, int defense, int hitPoints) { Type type = Assembly .GetCallingAssembly() .GetTypes() .First(t => t.Name == vehicleType); IAssembler assembler = new VehicleAssembler(); Object[] args = { model, weight, price, attack, defense, hitPoints, assembler }; IVehicle vehicle = (IVehicle)Activator.CreateInstance(type, args); return(vehicle); }
public void TotalWeightShouldReturnCorrectValue() { var arsenalPart = new ArsenalPart("model", 100, 10, 10); IAssembler assembler = new VehicleAssembler(); assembler.AddArsenalPart(arsenalPart); var assemblerTotalWeight = assembler.TotalWeight; IVehicle v = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); var expectedVehicleTotalWeight = v.Weight + assemblerTotalWeight; var actualVehicleTotalWeigth = v.TotalWeight; Assert.AreEqual(expectedVehicleTotalWeight, actualVehicleTotalWeigth); }
public void DoesTotalHitPointSumIsCorrest() { string model = "aaa"; double weight = 1; decimal price = 1; int attack = 1; int defense = 1; int hitpoint = 1; var assembler = new VehicleAssembler(); var revenger = new Revenger(model, weight, price, attack, defense, hitpoint, assembler); var endurance = new EndurancePart("aaa", 1, 1, 100); revenger.AddEndurancePart(endurance); Assert.AreEqual(101, revenger.TotalHitPoints); }
public void DoesTotalDefenseSumIsCorrest() { string model = "aaa"; double weight = 1; decimal price = 1; int attack = 1; int defense = 1; int hitpoint = 1; var assembler = new VehicleAssembler(); var revenger = new Revenger(model, weight, price, attack, defense, hitpoint, assembler); var shellpart = new ShellPart("aaa", 1, 1, 100); revenger.AddShellPart(shellpart); Assert.AreEqual(101, revenger.TotalDefense); }
public void CheckAddingItemsAndModifiengProperties() { string model = "Rhino-CE"; double weight = 10; decimal price = 10m; int attack = 10; int defense = 10; int hitPoints = 10; IAssembler assembler = new VehicleAssembler(); BaseVehicle testVehicle = new Revenger(model, weight, price, attack, defense, hitPoints, assembler); IPart arsenalPart = new ArsenalPart("shel1", 1, 1, 2); testVehicle.AddArsenalPart(arsenalPart); Assert.That(testVehicle.Parts.Count() == 1 && testVehicle.Parts.Contains(arsenalPart), "Arsenal part not added properly"); IPart shellPart = new ShellPart("shel1", 1, 1, 2); testVehicle.AddShellPart(shellPart); Assert.That(testVehicle.Parts.Count() == 2 && testVehicle.Parts.Contains(shellPart), "Shell part not added properly"); IPart endurancePart = new EndurancePart("shel1", 1, 1, 2); testVehicle.AddEndurancePart(endurancePart); Assert.That(testVehicle.Parts.Count() == 3 && testVehicle.Parts.Contains(endurancePart), "Endurance part not added properly"); double TotalWeightExpected = 3 + 10; Assert.AreEqual(TotalWeightExpected, testVehicle.TotalWeight); decimal TotalPriceExpected = 3 + 10; Assert.AreEqual(TotalPriceExpected, testVehicle.TotalPrice); long TotalAttackExpected = 10 + 2; Assert.AreEqual(TotalAttackExpected, testVehicle.TotalAttack); long TotalDefenseExpected = 10 + 2; Assert.AreEqual(TotalDefenseExpected, testVehicle.TotalDefense); long TotalHitPointsExpected = 10 + 2; Assert.AreEqual(TotalHitPointsExpected, testVehicle.TotalHitPoints); }
public void AddEndurancePartShouldAddThePartToOrderedParts() { //Arrange IPart part = new EndurancePart("part", 10, 10, 10); IAssembler assembler = new VehicleAssembler(); IVehicle vehicle = new Revenger("revenger", 10, 10, 10, 10, 10, assembler); //Action vehicle.AddEndurancePart(part); FieldInfo orderedPartsField = vehicle.GetType().BaseType.GetField("orderedParts", BindingFlags.NonPublic | BindingFlags.Instance); List <string> orderedParts = (List <string>)orderedPartsField.GetValue(vehicle); //Assert Assert.AreEqual(true, orderedParts[0] == part.Model); }
public void TestAddPartCorrectly() { IAssembler assembler = new VehicleAssembler(); Revenger revenger = new Revenger("Test", 100, 100, 100, 100, 100, assembler); ArsenalPart arsenalPart = new ArsenalPart("Arsenal", 23, 50, 5); EndurancePart endurancePart = new EndurancePart("Endurance", 23, 50, 5); ShellPart shellPart = new ShellPart("Shell", 23, 50, 5); Assert.DoesNotThrow(() => revenger.AddArsenalPart(arsenalPart)); Assert.DoesNotThrow(() => revenger.AddEndurancePart(endurancePart)); Assert.DoesNotThrow(() => revenger.AddShellPart(shellPart)); string actualResult = revenger.ToString(); string expectedResult = "Revenger - Test\r\nTotal Weight: 169.000\r\nTotal Price: 250.000\r\nAttack: 105\r\nDefense: 105\r\nHitPoints: 105\r\nParts: Arsenal, Endurance, Shell"; Assert.AreEqual(actualResult, expectedResult); }