public void FormatConvertorFacade_Call_All_Required_Methods_Test() { string expectedInputXmlContent = "cokoli"; FormatConvertorFacade formatConvertorFacade = new FormatConvertorFacade(deserializerFromXmlMock.Object, convertorFactoryMock.Object); // objekt ke konverzi DocToConvert docToConvert = new DocToConvert { TargetFormat = TargetFormatType.Json, XmlContent = expectedInputXmlContent, }; ConvertedResult convertedResult = formatConvertorFacade.GetConvertedResult(docToConvert); // ASSERT // že voláme metodu DeserializeFromXml s xml content z dodaného DocToConvert objektu deserializerFromXmlMock.Verify(x => x.DeserializeFromXml(It.Is <string>(s => s.Equals(expectedInputXmlContent))), Times.Once); // CreateObjectConvertor se správným TargetFormat convertorFactoryMock.Verify(x => x.CreateObjectConvertor(docToConvert.TargetFormat), Times.Once); //metoda SerializeObject zavolána s očekávaným objektem this.jsonConvertorMock.Verify(x => x.SerializeObject(It.Is <Notino_Homework_Stryncl.Models.Document>(d => d.Title == expectedDocument.Title && d.Text == expectedDocument.Text)), Times.Once); Assert.Equal(docToConvert.TargetFormat, convertedResult.TargetFormat); Assert.Equal(ExpectedJsonContent, convertedResult.Content); }
public ConvertedResult GetConvertedResult(DocToConvert docToConvert) { TargetFormatType requiredFormat = docToConvert.TargetFormat; Document document = this.deserializerFromXml.DeserializeFromXml(docToConvert.XmlContent); IObjectConvertor convertor = this.convertorFactory.CreateObjectConvertor(requiredFormat); string convertedContent = convertor.SerializeObject(document); return(new ConvertedResult() { TargetFormat = requiredFormat, Content = convertedContent }); }
public ConvertedResult Post(DocToConvert docToConvert) { return(this.convertorFacade.GetConvertedResult(docToConvert)); }