Exemplo n.º 1
0
        public void AdaptedJsonReader_Holds_Serializer_Properties()
        {
            var serializer = CustomJson.Serializer();

            using (var jsonReader = serializer.AdaptedJsonReader(TextReader.Null))
            {
                Assert.True(ReferenceEquals(jsonReader.Culture, serializer.Culture));
                Assert.True(jsonReader.DateParseHandling.Equals(serializer.DateParseHandling));
                Assert.True(jsonReader.DateFormatString.Equals(serializer.DateFormatString));
                Assert.True(jsonReader.DateTimeZoneHandling.Equals(serializer.DateTimeZoneHandling));
                Assert.True(jsonReader.FloatParseHandling.Equals(serializer.FloatParseHandling));
                Assert.True(jsonReader.MaxDepth.Equals(serializer.MaxDepth));
                Assert.True(jsonReader.CloseInput);
            }
        }
Exemplo n.º 2
0
        public void AdaptedJsonWriter_Holds_Serializer_Properties()
        {
            var serializer = CustomJson.Serializer();

            using (var jsonWriter = serializer.AdaptedJsonWriter(TextWriter.Null))
            {
                Assert.True(ReferenceEquals(jsonWriter.Culture, serializer.Culture));
                Assert.True(jsonWriter.DateFormatHandling.Equals(serializer.DateFormatHandling));
                Assert.True(jsonWriter.DateFormatString.Equals(serializer.DateFormatString));
                Assert.True(jsonWriter.DateTimeZoneHandling.Equals(serializer.DateTimeZoneHandling));
                Assert.True(jsonWriter.FloatFormatHandling.Equals(serializer.FloatFormatHandling));
                Assert.True(jsonWriter.Formatting.Equals(serializer.Formatting));
                Assert.True(jsonWriter.StringEscapeHandling.Equals(serializer.StringEscapeHandling));
                Assert.True(jsonWriter.CloseOutput);
            }
        }
Exemplo n.º 3
0
        public void It_Should_Get_Successfull_Response_After_Successfull_Add_Calculation_Entry()
        {
            //Arrange
            var expectedResult = new CustomJsonModel
            {
                Success = true,
            };
            MortgageController controller = new MortgageController(mortageServiceMock.Object);

            //Act
            var        controllerResult = controller.AddCalculationEntry(_mortgageEntry);
            CustomJson jsonResult       = controllerResult as CustomJson;

            //Assert
            Assert.AreEqual(expectedResult.Success, jsonResult.Data.Success);
        }
Exemplo n.º 4
0
        public void It_Should_Get_Successfull_Response_And_Message_After_Successfull_Email_Sent()
        {
            //Arrange
            var expectedResult = new CustomJsonModel {
                Success = true,
                Message = "Email sent successfully"
            };
            MortgageController controller = new MortgageController(mortageServiceMock.Object);

            //Act
            var        controllerResult = controller.SendMail(_mortgageEntry, _email);
            CustomJson jsonResult       = controllerResult as CustomJson;

            //Assert
            Assert.AreEqual(expectedResult.Success, jsonResult.Data.Success);
            Assert.AreEqual(expectedResult.Message, jsonResult.Data.Message);
        }
Exemplo n.º 5
0
        public void It_Should_Get_Successfull_Response_And_History_List_After_Successfull_Get_Entry_List()
        {
            //Arrange
            var expectedResult = new CustomJsonModel
            {
                Success = true,
                History = entryList
            };
            MortgageController controller = new MortgageController(mortageServiceMock.Object);

            //Act
            var        controllerResult = controller.GetHistoryList();
            CustomJson jsonResult       = controllerResult as CustomJson;

            //Assert
            Assert.AreEqual(expectedResult.Success, jsonResult.Data.Success);
            Assert.AreEqual(expectedResult.History.Count(), jsonResult.Data.History.Count());
        }
Exemplo n.º 6
0
        public void FromJsonGetNext_Works_As_Expected()
        {
            var data = "20.45";

            using (var jsonReader = data.CreateJsonReader())
            {
                Assert.True(jsonReader.Read());
                Assert.True(jsonReader.FromJsonGetNext <double>(CustomJson.Serializer()).Equals(20.45));
            }

            data = JsonConvert.SerializeObject(new TestClass {
                Name = "Testing"
            });
            using (var jsonReader = data.CreateJsonReader())
            {
                Assert.True(jsonReader.Read());
                Assert.True(jsonReader.FromJsonGetNext <TestClass>(CustomJson.Serializer()).Name.Equals("Testing"));
            }
        }
Exemplo n.º 7
0
        public void It_Should_Get_Not_Successfull_Message_And_Response_After_Failed_Email_Sent()
        {
            //Arrange
            var expectedResult = new CustomJsonModel
            {
                Success = false,
                Message = "There was an error when processing your request. Please try again"
            };

            mortageServiceMock.Setup(service => service.SendEmail(_mortgageEntry, _email)).Returns(false);
            MortgageController controller = new MortgageController(mortageServiceMock.Object);

            //Act
            var        controllerResult = controller.SendMail(_mortgageEntry, _email);
            CustomJson jsonResult       = controllerResult as CustomJson;

            //Assert
            Assert.AreEqual(expectedResult.Message, jsonResult.Data.Message);
            Assert.AreEqual(expectedResult.Success, jsonResult.Data.Success);
        }
Exemplo n.º 8
0
        public void It_Should_Get_Successfull_Response_And_Clean_History_List_After_Get_Entry_List_With_No_Entries()
        {
            //Arrange
            var expectedResult = new CustomJsonModel
            {
                Success = true,
                History = new List <MortgageEntry>()
            };

            mortageServiceMock.Setup(service => service.GetHistory()).Returns(new List <MortgageEntry>());
            MortgageController controller = new MortgageController(mortageServiceMock.Object);

            //Act
            var        controllerResult = controller.GetHistoryList();
            CustomJson jsonResult       = controllerResult as CustomJson;

            //Assert
            Assert.AreEqual(expectedResult.Success, jsonResult.Data.Success);
            Assert.AreEqual(expectedResult.History.Count(), jsonResult.Data.History.Count());
        }
Exemplo n.º 9
0
        public void It_Should_Get_Not_Successfull_Message_And_Response_When_Sent_Email_After_Bad_ViewModel_Data_Passed()
        {
            //Arrange
            var expectedResult = new CustomJsonModel
            {
                Success = false,
                Message = "There was an error when processing your request. Please try again"
            };
            var antoherMortageEntry = new MortgageEntryViewModel()
            {
                InterestRate = 9,
            };
            MortgageController controller = new MortgageController(mortageServiceMock.Object);

            //Act
            var        controllerResult = controller.SendMail(antoherMortageEntry, _email);
            CustomJson jsonResult       = controllerResult as CustomJson;

            //Assert
            Assert.AreEqual(expectedResult.Message, jsonResult.Data.Message);
        }
Exemplo n.º 10
0
        public void Serializer_Returns_A_New_Instance_Everytime_With_Consistent_Properties()
        {
            var first = CustomJson.Serializer();

            Assert.False(ReferenceEquals(first, CustomJson.Serializer()));
            Assert.False(first.CheckAdditionalContent);
            Assert.True(first.Culture.Equals(CultureInfo.CurrentCulture));
            Assert.True(first.DateFormatHandling.Equals(DateFormatHandling.IsoDateFormat));
            Assert.True(first.DateTimeZoneHandling.Equals(DateTimeZoneHandling.Utc));
            Assert.True(first.FloatFormatHandling.Equals(FloatFormatHandling.DefaultValue));
            Assert.True(first.Formatting.Equals(Formatting.None));
            Assert.True(first.StringEscapeHandling.Equals(StringEscapeHandling.Default));
            Assert.True(first.ConstructorHandling.Equals(ConstructorHandling.AllowNonPublicDefaultConstructor));
            Assert.True(first.DateParseHandling.Equals(DateParseHandling.DateTime));
            Assert.True(first.DefaultValueHandling.Equals(DefaultValueHandling.Ignore));
            Assert.True(first.FloatParseHandling.Equals(FloatParseHandling.Double));
            Assert.True(first.MissingMemberHandling.Equals(MissingMemberHandling.Ignore));
            Assert.True(first.NullValueHandling.Equals(NullValueHandling.Ignore));
            Assert.True(first.ObjectCreationHandling.Equals(ObjectCreationHandling.Auto));
            Assert.True(first.PreserveReferencesHandling.Equals(PreserveReferencesHandling.None));
            Assert.True(first.ReferenceLoopHandling.Equals(ReferenceLoopHandling.Error));
            Assert.True(first.TypeNameAssemblyFormatHandling.Equals(TypeNameAssemblyFormatHandling.Simple));
            Assert.True(first.TypeNameHandling.Equals(TypeNameHandling.Auto));
        }