Пример #1
0
        public void Add_Tag_To_Specified_Frames()
        {
            var tagAccess = new TagAccess();
            var builder   = new ContextFactoryBuilder();

            builder.WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 1
            }).WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 2
            });
            tagAccess.ContextFactory = builder.Build();

            tagAccess.AddTag("", new Position(0, 0), new[] { 1, 2 }, new Tag()
            {
                Title = "test tag"
            });
            tagAccess.GetTags("", new Position(0, 0), 1).Single().Title.Should().Be("test tag");
            tagAccess.GetTags("", new Position(0, 0), 2).Single().Title.Should().Be("test tag");
        }
Пример #2
0
        public void Find_Matching_Frames_Complex()
        {
            var frameAccess = new FrameAccess();
            var builder     = new ContextFactoryBuilder();

            builder.WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 1,
                Rax      = ((ulong)1).ToHexString()
            }).WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 2,
                Rax      = ((ulong)2).ToHexString()
            }).WithFrame(new FrameEntity
            {
                PosHi    = 1,
                PosLo    = 0,
                ThreadId = 2,
                Rax      = ((ulong)2).ToHexString()
            }).WithFrame(new FrameEntity
            {
                PosHi    = 1,
                PosLo    = 1,
                ThreadId = 2,
                Rax      = ((ulong)1).ToHexString(),
                Rbx      = ((ulong)2).ToHexString()
            });
            frameAccess.ContextFactory = builder.Build();

            var rax           = new RegisterEqualsCriterion(Register.Rax, ((ulong)1).ToHexString());
            var rbx           = new RegisterEqualsCriterion(Register.Rbx, ((ulong)2).ToHexString());
            var and           = new AndCriterion(new[] { rax, rbx });
            var or            = new OrCriterion(new[] { rax, rbx });
            var not           = new NotCriterion(rax);
            var all           = new OrCriterion(new ICriterion[] { not, rax });
            var none          = new AndCriterion(new ICriterion[] { not, rax });
            var andAll        = new AndCriterion(new ICriterion[] { and, all });
            var andResults    = frameAccess.Search("", and);
            var orResults     = frameAccess.Search("", or);
            var notResults    = frameAccess.Search("", not);
            var allResults    = frameAccess.Search("", all);
            var noneResults   = frameAccess.Search("", none);
            var andAllResults = frameAccess.Search("", andAll);

            andResults.Single().RegisterSet.Rax.Should().Be(1);
            andResults.Single().RegisterSet.Rbx.Should().Be(2);

            orResults.Should().HaveCount(2);
            notResults.Should().HaveCount(2);
            allResults.Should().HaveCount(4);
            noneResults.Should().HaveCount(0);
            andAllResults.Should().HaveCount(1);
        }
Пример #3
0
        public void Throw_Application_Exception_If_Save_Fails()
        {
            var frameAccess = new FrameAccess();
            var builder     = new ContextFactoryBuilder();

            builder.WithContext(new CantSaveContext());
            frameAccess.ContextFactory = builder.Build();
            Action a = () => frameAccess.UpsertFrames("", new List <Frame>());

            a.Should().Throw <ApplicationException>();
        }
Пример #4
0
        public void Find_Matching_Frames_By_Register_values()
        {
            var frameAccess = new FrameAccess();
            var builder     = new ContextFactoryBuilder();

            builder.WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 1,
                Rax      = ((ulong)0).ToHexString(),
                Rbx      = ((ulong)1).ToHexString(),
                Rcx      = ((ulong)2).ToHexString(),
                Rdx      = ((ulong)3).ToHexString()
            }).WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 2,
                Rax      = ((ulong)0).ToHexString(),
                Rbx      = ((ulong)2).ToHexString(),
                Rcx      = ((ulong)4).ToHexString(),
                Rdx      = ((ulong)6).ToHexString()
            }).WithFrame(new FrameEntity
            {
                PosHi    = 1,
                PosLo    = 0,
                ThreadId = 2
            }).WithFrame(new FrameEntity
            {
                PosHi    = 1,
                PosLo    = 1,
                ThreadId = 2,
                Rax      = ((ulong)0).ToHexString(),
                Rbx      = ((ulong)1).ToHexString(),
                Rcx      = ((ulong)2).ToHexString(),
                Rdx      = ((ulong)3).ToHexString()
            });
            frameAccess.ContextFactory = builder.Build();

            var between =
                new RegisterBetweenCriterion(Register.Rax, ((ulong)0).ToHexString(), ((ulong)2).ToHexString());
            var notBetween = new NotCriterion(between);

            var betweenResults    = frameAccess.Search("", between);
            var notBetweenResults = frameAccess.Search("", notBetween);

            betweenResults.Should().HaveCount(3);
            notBetweenResults.Should().HaveCount(1);
        }
Пример #5
0
        public void Throw_If_Frame_Cant_Be_Found()
        {
            var access  = new FrameAccess();
            var builder = new ContextFactoryBuilder();
            var frame   = new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 1
            };

            builder.WithFrame(frame);
            access.ContextFactory = builder.Build();
            Action throws = () => access.GetFrame("test", new Position(1, 0), 1);

            throws.Should().Throw <IndexOutOfRangeException>();
        }
Пример #6
0
        public void Get_The_Correct_Frame_If_One_Exists()
        {
            var access  = new FrameAccess();
            var builder = new ContextFactoryBuilder();
            var frame   = new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 1
            };

            builder.WithFrame(frame);
            access.ContextFactory = builder.Build();
            var converter = new FrameDomainEntityConverter();
            var domain    = converter.ToDomain(frame, access.ContextFactory.GetContext(""));

            access.GetFrame("anyproject", new Position(0, 0), 1).Should().Be(domain);
        }
        public void Convert_Between_Tag_And_TagEntity()
        {
            var builder = new ContextFactoryBuilder();
            var fac     = builder.Build();
            var context = fac.GetContext("");
            var tag     = new Tag();

            tag.CreateDateUtc = DateTime.MinValue;
            tag.Title         = "hello there";
            tag.Body          = "body";
            var converter = new TagDomainEntityConverter();
            var converted = converter.ToEntity(tag, context);

            converted.Title.Should().Be("hello there");
            converted.Body.Should().Be("body");
            var convertedBack = converter.ToDomain(converted, context);

            convertedBack.Title.Should().Be("hello there");
            convertedBack.Body.Should().Be("body");
            convertedBack.CreateDateUtc.Should().Be(DateTime.MinValue);
        }
        public void Return_The_Existing_Tag_If_One_Exists()
        {
            var       id      = Guid.NewGuid();
            var       dc      = DateTime.UtcNow;
            var       builder = new ContextFactoryBuilder();
            TagEntity tag     = new TagEntity()
            {
                Id            = id,
                Body          = "body",
                Title         = "title",
                CreateDateUtc = dc
            };

            builder.WithTag(tag);
            var fac       = builder.Build();
            var context   = fac.GetContext("");
            var converter = new TagDomainEntityConverter();

            converter.ToEntity(new Tag()
            {
                Id = id
            }, context).Should().BeSameAs(tag);
        }
Пример #9
0
        public void Find_Matching_Frames_When_Searched_For_Basic()
        {
            var frameAccess = new FrameAccess();
            var builder     = new ContextFactoryBuilder();

            builder.WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 1,
                Rax      = ((ulong)1).ToHexString()
            }).WithFrame(new FrameEntity
            {
                PosHi    = 0,
                PosLo    = 0,
                ThreadId = 2,
                Rax      = ((ulong)2).ToHexString()
            });
            frameAccess.ContextFactory = builder.Build();

            var results = frameAccess.Search("", new RegisterEqualsCriterion(Register.Rax, ((ulong)1).ToHexString()));

            results.Single().RegisterSet.Rax.Should().Be(1);
        }
Пример #10
0
        public void Create_The_Correct_Expression_Tree_For_Or()
        {
            var visitor   = new FrameCriterionVisitor();
            var criteria1 = new RegisterEqualsCriterion(Register.Rax, ((ulong)0).ToHexString());
            var criteria2 = new RegisterEqualsCriterion(Register.Rbx, ((ulong)1).ToHexString());
            var and       = new OrCriterion(new[] { criteria1, criteria2 });
            var f         = visitor.Visit(and);
            var builder   = new ContextFactoryBuilder();
            var frame     = new FrameEntity
            {
                Rax = ((ulong)0).ToHexString(),
                Rbx = ((ulong)1).ToHexString()
            };
            var frame2 = new FrameEntity
            {
                Rax = ((ulong)1).ToHexString(),
                Rbx = ((ulong)1).ToHexString()
            };

            builder.WithFrame(frame).WithFrame(frame2);
            var method = ((FramePredicateExpression)f).Compile();

            new[] { frame, frame2 }.Where(x => method(x)).SequenceEqual(new[] { frame, frame2 }).Should().BeTrue();
        }