public void Can_Get_Right_Xml_With_Note_Content_Contains_Invalid_Char_To_DataSource() { // Arrange - note with null content var xmlDoc = XDocument.Parse($"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{XmlNamespace}\"><Content><Automobile><Maker>Subaru</Maker><Brand><Outback></Brand><Year>2017</Year><Color>Blue</Color><Pin>135</Pin><Plate>BCTT208</Plate><MeterReading>1234535</MeterReading></Automobile></Content></Note>"); // Note: Outback is surrounding by bracket to test escape special character in class var auto = new AutomobileInfo { Maker = "Subaru", Brand = "<Outback>", Year = "2017", Color = "Blue", Pin = "135", Plate = "BCTT208", MeterReading = 1234535 }; // Act var note = _noteSerializer.GetNote(auto); // Assert Assert.True(_noteSerializer.ProcessResult.Success); Assert.NotNull(note); Assert.Equal(note.Content, xmlDoc.ToString(SaveOptions.DisableFormatting)); Assert.Contains("<", note.Content); Assert.Contains(">", note.Content); }
public void Can_Parse_Automobile_String_Content(string contentText) { // Arrange var xmlDoc = XDocument.Parse(string.Format(NoteXmlTextBase, XmlNamespace, contentText)); var auto = new AutomobileInfo { Maker = "Subaru", Brand = "Outback", Year = "2017", Color = "Blue", Pin = "135", Plate = "BCTT208", MeterReading = 1234535 }; // Act var note = _noteSerializer.GetNote(auto); // Assert Assert.True(_noteSerializer.ProcessResult.Success); Assert.NotNull(note); Assert.Equal(AutomobileConstant.AutoMobileRecordSubject, note.Subject); Assert.Equal(note.Content, xmlDoc.ToString(SaveOptions.DisableFormatting)); }
private IEnumerable <AutomobileInfo> SetupEnvironment() { var author = AuthorRepository.GetEntities().FirstOrDefault(); var car = new AutomobileInfo { Brand = "AutoBack", Maker = "Subaru", MeterReading = 100, Year = "2018", Pin = "1234", Plate = "BCTT208", Color = "Blue" }; Assert.NotNull(author); _manager.Create(car); return(_manager.GetEntities(new ResourceCollectionParameters()).ToList()); }
public void Can_Get_Automobile_By_Parse_Valid_Note_Xml() { // Arrange var xmlDoc = XDocument.Parse($"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{XmlNamespace}\"><Content><Automobile><Maker>Subaru</Maker><Brand>Outback</Brand><Year>2017</Year><Color>Blue</Color><Pin>135</Pin><Plate>BCTT208</Plate><MeterReading>1234535</MeterReading></Automobile></Content></Note>"); var note = new HmmNote { Id = 1, Author = _author, Subject = AutomobileConstant.AutoMobileRecordSubject, Content = xmlDoc.ToString(SaveOptions.DisableFormatting), CreateDate = DateTime.Now, LastModifiedDate = DateTime.Now }; var autoExpected = new AutomobileInfo { Id = 1, Maker = "Subaru", Brand = "Outback", Year = "2017", Color = "Blue", Pin = "135", Plate = "BCTT208", MeterReading = 1234535, }; // Act var auto = _noteSerializer.GetEntity(note); // Assert Assert.True(_noteSerializer.ProcessResult.Success); Assert.NotNull(auto); Assert.Equal(autoExpected.Id, auto.Id); Assert.Equal(autoExpected.Maker, auto.Maker); Assert.Equal(autoExpected.Brand, auto.Brand); Assert.Equal(autoExpected.Year, auto.Year); Assert.Equal(autoExpected.Color, auto.Color); Assert.Equal(autoExpected.Pin, auto.Pin); Assert.Equal(autoExpected.Plate, auto.Plate); Assert.Equal(_author.Id.ToString(), auto.AuthorId.ToString()); }
public void CanCreateAutoMobile() { // Arrange var car = new AutomobileInfo { Brand = "AutoBack", Maker = "Subaru", MeterReading = 100, Year = "2018", Pin = "1234", Color = "Blue", Plate = "BCTT208" }; // Act var savedCar = _manager.Create(car); // Assert Assert.True(_manager.ProcessResult.Success); Assert.NotNull(savedCar); Assert.True(savedCar.Id >= 1, "car.Id >= 1"); }
public void AutoMustHaveValid_Author() { // Arrange var auto = new AutomobileInfo { Brand = "Outback", Maker = "Subaru", MeterReading = 100, Year = "2018", Pin = "1234", Plate = "BCTT208", Color = "Blue" }; // Act var processResult = new ProcessingResult(); var result = _validator.IsValidEntity(auto, processResult); // Assert Assert.False(result); Assert.Single(processResult.MessageList); }
public void Can_Get_Right_Xml_With_Null_Note_Content_To_DataSource() { // Arrange - note with null content var auto = new AutomobileInfo { Maker = "Subaru", Brand = "Outback", Year = "2017", Color = "Blue", Pin = "135", MeterReading = 1234535 }; var xmlDoc = XDocument.Parse( $"<?xml version=\"1.0\" encoding=\"utf-16\" ?><Note xmlns=\"{XmlNamespace}\"><Content><Automobile><Maker>Subaru</Maker><Brand>Outback</Brand><Year>2017</Year><Color>Blue</Color><Pin>135</Pin><Plate /><MeterReading>1234535</MeterReading></Automobile></Content></Note>"); // Act var note = _noteSerializer.GetNote(auto); // Assert Assert.True(_noteSerializer.ProcessResult.Success); Assert.Equal(note.Content, xmlDoc.ToString(SaveOptions.DisableFormatting)); Assert.NotNull(note); }
public void ValidAutomobileInfo_CanPassValidation() { // Arrange var auto = new AutomobileInfo { AuthorId = _authorId, Brand = "Outback", Maker = "Subaru", MeterReading = 100, Year = "2018", Pin = "1234", Plate = "BCTT208", Color = "Blue" }; // Act var processResult = new ProcessingResult(); var result = _validator.IsValidEntity(auto, processResult); // Assert Assert.True(result); Assert.Empty(processResult.MessageList); }
public void ValidGasLogCanPassValidation() { // Arrange var log = new GasLog { AuthorId = _authorId, Date = DateProvider.UtcNow, Car = new AutomobileInfo(), CurrentMeterReading = 30000.GetKilometer(), Distance = 340.GetKilometer(), Gas = 40d.GetLiter(), Price = 1.34m.GetCad(), Station = "Costco", CreateDate = DateProvider.UtcNow, Discounts = new List <GasDiscountInfo> { new() { Program = new GasDiscount { Amount = 0.8m.GetCad(), Program = "Petro-Canada membership", DiscountType = GasDiscountType.PerLiter, AuthorId = _authorId }, Amount = 0.8m.GetCad() } },
private static (bool isValid, string validationError) MeterReadingValid(GasLog log, AutomobileInfo auto) { if (log == null) { throw new ArgumentNullException(nameof(log)); } if (auto == null) { throw new ArgumentNullException(nameof(auto)); } if (auto.MeterReading <= 0) { return(false, "The automobile's meter reading is invalid"); } // automobile's meter reading should less then new meter reading if (auto.MeterReading > log.CurrentMeterReading.TotalKilometre) { return(false, "The automobile's meter reading is larger then gas log"); } // the difference between current automobile meter reading and new meter reading should greater then log distance if (log.CurrentMeterReading - Dimension.FromKilometer(auto.MeterReading) < log.Distance) { return(false, "The logging distance is invalid"); } return(log.CurrentMeterReading - Dimension.FromKilometer(auto.MeterReading) != log.Distance ? (true, "Current log distance plus automobile's current meter reading does not match log's current meter reading") : (true, string.Empty)); }