Esempio n. 1
0
        public void Successfully_PostsDiverge_Stored()
        {
            var post1  = new RollPost();
            var post2  = new RollPost();
            var stream = new MemoryStream();

            post1.AddRoll("1d20", Roll9Conf);
            post1.AddRoll("1d20", Roll9Conf);
            post2.AddRoll("1d20", Roll9Conf);
            post2.AddRoll("1d20", Roll1Conf);
            post1.Validate();
            post2.Validate();

            post1.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post3 = RollPost.Deserialize(stream);

            stream.Dispose();

            stream = new MemoryStream();
            post2.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post4 = RollPost.Deserialize(stream);

            stream.Dispose();

            Assert.IsTrue(post3.HasDivergedFrom(post4));
        }
Esempio n. 2
0
        public void Successfully_NotValidate_WhenKeepingStoredPost()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            post.AddRoll("1d20");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            post2.AddRoll("1d20+1");
            EatExceptions(() => post2.AddRoll("q"));
            post2.Validate();

            stream.Dispose();
            stream = new MemoryStream();
            post2.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post3 = RollPost.Deserialize(stream);

            post3.AddRoll("1d20+1");
            EatExceptions(() => post3.AddRoll("q"));

            Assert.IsFalse(post3.Validate());
            Assert.AreEqual(post3.Stored[0], post3.Current[0]);
        }
Esempio n. 3
0
        public void Successfully_ChangeInvalidToValid_Stored()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            post.AddRoll("1d20");
            post.AddRoll("1d20");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            EatExceptions(DiceErrorCode.ParseError, () => post2.AddRoll("qwerty"));
            post2.AddRoll("1d20", Roll9Conf);
            post2.Validate();

            stream.Dispose();
            stream = new MemoryStream();
            post2.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post3 = RollPost.Deserialize(stream);

            post3.AddRoll("1d20+1");
            post3.AddRoll("1d20", Roll20Conf);

            Assert.IsFalse(post3.Validate());
            Assert.AreEqual(post3.Stored[1], post3.Current[1]);
            Assert.AreEqual(1, post3.Diverged);
        }
Esempio n. 4
0
        public void Successfully_NotValidate_WhenRemovingRolls()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            post.AddRoll("1d20");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            Assert.IsFalse(post2.Validate());
        }
Esempio n. 5
0
        public void Successfully_Validate_WhenSavedPostMatches()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            post.AddRoll("1d20");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            post2.AddRoll("1d20");

            Assert.IsTrue(post2.Validate());
        }
Esempio n. 6
0
        public void Successfully_NotValidate_WhenChangingRollToInvalid()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            post.AddRoll("1d20");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            EatExceptions(DiceErrorCode.ParseError, () => post2.AddRoll("qwerty"));

            Assert.IsFalse(post2.Validate());
            Assert.AreEqual(RollResult.InvalidRoll, post2.Current[0]);
        }
Esempio n. 7
0
        public void Successfully_Validate_WhenChangingInvalidRollToValid()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            EatExceptions(DiceErrorCode.ParseError, () => post.AddRoll("qwerty"));
            post.AddRoll("1d20");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            post2.AddRoll("1d20");
            post2.AddRoll("1d20");

            Assert.IsTrue(post2.Validate());
            Assert.AreEqual(0, post2.Diverged);
        }
Esempio n. 8
0
        public void Successfully_PreserveMetadata()
        {
            var metadata = "foobar";
            var stream   = new MemoryStream();
            var post     = new RollPost();

            post.AddRoll("1d20", null, new RollData()
            {
                Metadata = metadata
            });
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            post2.AddRoll("1d20");
            post2.Validate();

            Assert.AreEqual(metadata, (string)post2.Current[0].Metadata);
        }
        public void Successfully_RoundtripRollPost_ForPersistence()
        {
            var stream = new MemoryStream();
            var post   = new RollPost();

            post.AddRoll("20d20+4");
            post.AddRoll("2d6+3");
            post.AddRoll("[roll:2]-2");
            post.Validate();

            post.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var post2 = RollPost.Deserialize(stream);

            CollectionAssert.AreEqual(post.Pristine.ToList(), post2.Pristine.ToList());
            CollectionAssert.AreEqual(post.Current.ToList(), post2.Stored.ToList());
            CollectionAssert.AreEqual(new List <RollResult>(), post2.Current.ToList());
            Assert.AreEqual(0, post2.Diverged);

            post2.AddRoll("10d20+4");
            Assert.AreEqual(2, post2.Diverged);
        }