public void TestSpeakerTransformFromPoco() { // given var expectedId = "1"; var expectedhref = "https://test.com/TestHREF/" + expectedId; var expectedName = "Scott Guthrie"; var poco = new PocoReturnData { href = expectedhref, data = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "name", "Name" }, { "value", expectedName } } } }; // when var result = Speaker.SpeakerFromPoco(poco); // then Assert.IsNotNull(result, "Result is null"); Assert.AreEqual(expectedId, result.SpeakerId); Assert.AreEqual(expectedName, result.Name); }
public void TestGetPocoValuet() { // given var expectedId = "1"; var expectedhref = "https://test.com/TestHREF/" + expectedId; var expectedName = "Scott Guthrie"; var poco = new PocoReturnData { href = expectedhref, data = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "name", "unexpected" }, { "value", "thisisnotthedata" } }, new Dictionary <string, string>() { { "name", "Name" }, { "value", expectedName } } } }; // when var actualName = BaseModel.GetPocoValue(poco, "Name"); // then Assert.AreEqual(expectedName, actualName); }
public static Speaker SpeakerFromPoco(PocoReturnData pocoSpeaker) { return(new Speaker { SpeakerId = new Uri(pocoSpeaker.href).Segments.LastOrDefault(), Name = GetPocoValue(pocoSpeaker, "Name") }); }
public static Topic TopicFromPoco(PocoReturnData poco) { return(new Topic { TopicId = new Uri(poco.href).Segments.LastOrDefault(), Title = GetPocoValue(poco, "Title") }); }
public static Session SessionFromPoco(PocoReturnData poco) { return(new Session { SessionId = new Uri(poco.href).Segments.LastOrDefault(), Title = GetPocoValue(poco, "Title"), Slottime = GetPocoValue(poco, "Timeslot"), SpeakersName = GetPocoValue(poco, "Speaker"), Topics = new Topics() }); }
public static string GetPocoValue(PocoReturnData poco, string valueName) { var item = poco.data.FirstOrDefault(w => w.ContainsValue(valueName)); var value = "unknown"; if (!(item is null)) { value = item.FirstOrDefault(x => x.Key.Equals("value")).Value; } return(value); }
public void TestSpeakersTransformFromPoco() { // given var expectedName = "Scott Guthrie"; var poco1 = new PocoReturnData { href = "https://test.com/TestHREF/1", data = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "name", "Name" }, { "value", expectedName } } } }; var poco2 = new PocoReturnData { href = "https://test.com/TestHREF/2", data = new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "name", "Name" }, { "value", "John Jones" } } } }; var pocos = new List <PocoReturnData> { poco1, poco2 }; // when var result = Speakers.SpeakersFromPoco(pocos); // then Assert.IsNotNull(result.Items, "Items is null"); Assert.AreEqual(2, result.Items.Count); }
public async Task TestNoException_AllGetSessionAndTopicSpecialAsync() { // large test shouldn't be done like this, // I should test each method that makes up this bigger // I've spent enough time so this is showing async testing + mocking // given var mockClient = new Mock <IConferenceClient>(); var confquery = new ConferenceQuery(mockClient.Object); var expectedSpeaker = "Kit"; var speakerReturn = new PocoReturnData { href = "https://test.com/value/1", data = new List <Dictionary <string, string> > { new Dictionary <string, string> { { "name", "Name" }, { "value", expectedSpeaker } } } }; var speakersReturn = new List <PocoReturnData> { speakerReturn }; mockClient .Setup(x => x.GetSpeakersAsync(It.IsAny <string>())) .ReturnsAsync(speakersReturn); var sessionReturn = new PocoReturnData { href = "https://test.com/value/11", data = new List <Dictionary <string, string> > { new Dictionary <string, string> { { "name", "Title" }, { "value", "Knight Rider" } }, new Dictionary <string, string> { { "name", "Timeslot" }, { "value", "04 December 2013 11:40 - 12:40" } }, new Dictionary <string, string> { { "name", "Speaker" }, { "value", expectedSpeaker } } } }; var sessionsReturn = new List <PocoReturnData> { sessionReturn }; mockClient .Setup(x => x.GetSpeakerSessionsAsync(It.IsAny <string>())) .ReturnsAsync(sessionsReturn); var topicsReturn = new List <PocoReturnData>(); mockClient .Setup(x => x.GetSessionTopicsAsync(It.IsAny <string>())) .ReturnsAsync(topicsReturn); // when -> then Assert.DoesNotThrowAsync(async() => await confquery.GetSessionAndTopicSpecialAsync(expectedSpeaker, new DateTime(), "5-6")); }