public void Index() { // Arrange HomeController controller = new HomeController(); var fakeRepo = new WebTextRepoMock(); controller.WebTextRepo = fakeRepo; // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.AreEqual("Shorjini Kempo Camp Stockholm 2014 homepage", result.ViewBag.Message); }
// [TestMethod] public void Get_ReqBody_XmlDoc() { //Arrange IWebTextRepo webTextRepo = new WebTextRepoMock(); ITranslatorRepo translatorRepo = new TranslatorRepo(); string sourceLang = "en"; string targetLang = "sv"; string body = "<TranslateArrayRequest>" + "<AppId />" + "<From>{0}</From>" + "<Options>" + " <Category xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" + "<ContentType xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\">{1}</ContentType>" + "<ReservedFlags xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" + "<State xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" + "<Uri xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" + "<User xmlns=\"http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\" />" + "</Options>" + "<Texts>" + "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">{2}</string>" + "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">{3}</string>" + "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">{4}</string>" + "</Texts>" + "<To>{5}</To>" + "</TranslateArrayRequest>"; List<WebText> webTextList = webTextRepo.ListWebTextForLang(language: sourceLang); string reqBody = string.Format(body, sourceLang, "text/plain", webTextList[0].HtmlText, webTextList[1].HtmlText, webTextList[2].HtmlText, targetLang); //Act //XDocument xbody = new XDocument( // new XElement("TranslateArrayRequest", // new XElement("AppId"), // new XElement("From", sourceLang), // new XElement("Options", // new XElement("Category", // new XAttribute("xmlns", // "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2\\") // ) // ) // ) // ); //XDocument xbody = // new XDocument( // new XElement("TranslateArrayRequest", // new XElement("AppId"), // new XElement("From",sourceLang), // new XElement("Options", // new XElement("Category", // new XAttribute("xmlns", "foo") // ) // ) // ) // ); XNamespace catNs = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"; XNamespace contNs = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"; XNamespace resNs = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"; XNamespace stateNs = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"; XNamespace uriNs = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"; XNamespace userNs = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"; XNamespace arrNs = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"; XDocument xbody = new XDocument( new XElement("TranslateArrayRequest", new XElement("AppId"), new XElement("From",sourceLang), new XElement("Options", new XElement("Category", new XAttribute(XNamespace.Xmlns +"catNS", catNs)), new XElement("ContentType", new XAttribute(XNamespace.Xmlns +"contNs", contNs)), new XElement("ReservedFlags", new XAttribute(XNamespace.Xmlns +"resNs", resNs)), new XElement("State", new XAttribute(XNamespace.Xmlns +"stateNs", stateNs)), new XElement("Uri", new XAttribute(XNamespace.Xmlns +"uriNs", uriNs)), new XElement("User", new XAttribute(XNamespace.Xmlns +"userNs", userNs)), new XElement("Texts",webTextList.Select(wt =>new XElement("string", new XAttribute(XNamespace.Xmlns + "arrNs", arrNs),wt.HtmlText)) )))); string fooXml = xbody.ToString(); var xmlReqBody = translatorRepo.ReqBody(webTextList, sourceLang, targetLang); //Assert Assert.AreEqual(xbody.ToString(), reqBody,"The xml document in the translation for array are not same as the hardcoded"); }
// [TestMethod] public void Translate_All_For_Japanese() { //Arrange TranslateController controller = new TranslateController(); //ITranslatorRepo translatorRepoMock = new TranslatorRepoMock(); // ITranslatorRepo translatorRepo = new TranslatorRepo(); //controller.translatorRepo = translatorRepo; IWebTextRepo webTextRepo = new WebTextRepoMock(); controller.WebTextRepo = webTextRepo; //Act List<WebText> translatedWebText = controller.TranslateWebTexts("en", "sv"); // controller.TranslateAll("en", "sv", "Home"); //Assert Assert.AreEqual(translatedWebText[0].HtmlText,"Senaste nytt"); }