Exemplo n.º 1
0
        public void CanSerializeDeserializeWatchList()
        {
            WatchList expected = null;
            WatchList actual   = null;
            var       data     = string.Empty;

            var now = DateTime.UtcNow;

            now = new DateTime(now.Ticks - (now.Ticks % TimeSpan.TicksPerSecond), now.Kind);

            "Given an instance object of WatchList"
            .x(() =>
            {
                expected = new WatchList
                {
                    Id     = Guid.NewGuid().ToString(),
                    Name   = "Default",
                    Assets = new List <string> {
                        "EURUSD", "EURGBP"
                    },
                    ViewType          = "FE",
                    ModifiedTimestamp = now,
                };
            });

            "When serialized to Dictionary<string, string>"
            .x(() =>
            {
                var dictionary = expected.ToMetadataDictionary();
                data           = JsonConvert.SerializeObject(dictionary);
            });

            "And deserialized back to WatchList"
            .x(() =>
            {
                actual = data.To <Dictionary <string, string> >().To <WatchList>();
            });

            "Then deserialized WatchList should be same as given WatchList"
            .x(() =>
            {
                actual.Should().BeEquivalentTo(expected);
            });
        }