public void WebServiceHeaderBuilder_GivenEmptyHeaders_SetHeaders() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var jsonHeader = new NameValue(); newMock.Object.Headers = new ObservableCollection <INameValue> { jsonHeader, new NameValue() }; var content = "{\"NormalText\":\"\"}"; //---------------Assert Precondition---------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); var countContentTypes = newMock.Object.Headers.Count(value => value.Name.Equals(GlobalConstants.ContentType)); var countContentTypesValues = newMock.Object.Headers.Count(value => value.Value.Equals(GlobalConstants.ApplicationJsonHeader)); Assert.AreEqual(1, countContentTypesValues); Assert.AreEqual(1, countContentTypes); }
public void WebServiceHeaderBuilder_GivenHasExistingXmlHeaderAndCOntentIsXml_PassAddNoHeaders() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var jsonHeader = new NameValue(GlobalConstants.ContentType, GlobalConstants.ApplicationXmlHeader); newMock.Object.Headers = new ObservableCollection <INameValue> { jsonHeader, new NameValue() }; var content = "<DataList><a>2</a></DataList>"; //---------------Assert Precondition---------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); var countContentTypes = newMock.Object.Headers.Count(value => value.Name.Equals(GlobalConstants.ContentType)); var countContentTypesValues = newMock.Object.Headers.Count(value => value.Value.Equals(GlobalConstants.ApplicationXmlHeader)); Assert.AreEqual(1, countContentTypesValues); Assert.AreEqual(1, countContentTypes); }
public void BuildHeader_GivenHasExistingJsonHeaderAndContentIsJson_PassAddNoHeaders() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var jsonHeader = new NameValue("Content-Type", "application/json"); newMock.Object.Headers = new ObservableCollection <INameValue> { jsonHeader, new NameValue() }; var content = "{\"NormalText\":\"\"}"; //---------------Assert Precondition---------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); var countContentTypes = newMock.Object.Headers.Count(value => value.Name.Equals("Content-Type")); var countContentTypesValues = newMock.Object.Headers.Count(value => value.Value.Equals("application/json")); Assert.AreEqual(1, countContentTypesValues); Assert.AreEqual(1, countContentTypes); }
public void WebServiceHeaderBuilder_GivenNoHeadersNoContent_PassThrouh() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.Setup(region => region.Headers).Returns(default(ObservableCollection <INameValue>)); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, null); //------------Assert Results------------------------- }
public void WebServiceHeaderBuilder_GivenEmptyJson_ExpectNull() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var content = "{}"; //this causes header: "Content-Type: application/json" misuse BUG: 6713 //---------------Assert Precondition---------------- Assert.IsNull(newMock.Object.Headers); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNull(newMock.Object.Headers, "Empty JSON causes header: Content-Type: application/json misuse BUG: 6713"); }
public void WebServiceHeaderBuilder_GivenNormalText_PassAddNoHeaders() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var content = "NormalText"; //---------------Assert Precondition---------------- Assert.IsNull(newMock.Object.Headers); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNull(newMock.Object.Headers); }
public void WebServiceHeaderBuilder_GivenNormalTextJson_PassAddHeaders() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var content = "{\"NormalText\":\"\"}"; //---------------Assert Precondition---------------- Assert.IsNull(newMock.Object.Headers); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); var countContentTypes = newMock.Object.Headers.Count(value => value.Name.Equals(GlobalConstants.ContentType)); var countContentTypesValues = newMock.Object.Headers.Count(value => value.Value.Equals("application/json")); Assert.AreEqual(1, countContentTypesValues); Assert.AreEqual(1, countContentTypes); }
public void BuildHeader_GivenNormalTextXml_PassAddHeaders() { //------------Setup for test-------------------------- var mod = new WebServiceHeaderBuilder(); var newMock = new Mock <IHeaderRegion>(); newMock.SetupProperty(region => region.Headers); var content = "<DataList><a>2</a></DataList>"; //---------------Assert Precondition---------------- Assert.IsNull(newMock.Object.Headers); //------------Execute Test--------------------------- mod.BuildHeader(newMock.Object, content); //------------Assert Results------------------------- Assert.IsNotNull(newMock.Object.Headers); Assert.AreEqual(2, newMock.Object.Headers.Count); var countContentTypes = newMock.Object.Headers.Count(value => value.Name.Equals("Content-Type")); var countContentTypesValues = newMock.Object.Headers.Count(value => value.Value.Equals("application/xml")); Assert.AreEqual(1, countContentTypesValues); Assert.AreEqual(1, countContentTypes); }
public void WebServiceHeaderBuilder_Ctor() { var mod = new WebServiceHeaderBuilder(); Assert.IsNotNull(mod); }