Exemplo n.º 1
0
        public void WithContent_AccpetsAnObjectAndAnAmlSerializer_SerializesTheObjectCorrectly()
        {
            var dummyUserResponseObject = new DummyUserResponseObject
            {
                EmailAddress  = "*****@*****.**",
                FistName      = "Bob",
                LastName      = "Martin",
                MonthlyIncome = 10000
            };

            var response = new ResponseBuilder()
                           .WithContent(dummyUserResponseObject, new XmlContentSerializer())
                           .WithStatusCode(HttpStatusCode.OK)
                           .Build();

            var stringBuilder = new StringBuilder();

            using (var stringWriter = new StringWriter(stringBuilder))
            {
                var xmlSerializer = new XmlSerializer(dummyUserResponseObject.GetType());
                xmlSerializer.Serialize(stringWriter, dummyUserResponseObject);
            }

            response.Content
            .Should().Be(stringBuilder.ToString());
        }
Exemplo n.º 2
0
        public void WithContent_AccpetsAnObjectAndAJsonSerializer_SerializesTheObjectCorrectly()
        {
            var dummyUserResponseObject = new DummyUserResponseObject
            {
                EmailAddress  = "*****@*****.**",
                FistName      = "Bob",
                LastName      = "Martin",
                MonthlyIncome = 10000
            };

            var response = new ResponseBuilder()
                           .WithContent(dummyUserResponseObject, new JsonContentSerializer())
                           .WithStatusCode(HttpStatusCode.OK)
                           .Build();


            string serializedString = JsonConvert.SerializeObject(dummyUserResponseObject);

            response.Content
            .Should().Be(serializedString);
        }