Ejemplo n.º 1
0
        public void Draw_WithoutContent_DoesNotThrow()
        {
            var arrowMock = new GraphicComponentMock();
            var container = CreateContainer(arrowMock);

            Assert.DoesNotThrow(() => container.Draw());
        }
Ejemplo n.º 2
0
 public void Setup()
 {
     lookingDown = new GraphicComponentMock();
     lookingLeft = new GraphicComponentMock();
     lookingRight = new GraphicComponentMock();
     lookingUp = new GraphicComponentMock();
 }
Ejemplo n.º 3
0
        public void PreferredHeight_ContentWithPreferredHeight_EqualsContentsPreferredHeight()
        {
            var arrowMock = new GraphicComponentMock();
            var contentMock = new GraphicComponentMock() { PreferredHeight = 10 };
            var container = CreateContainer(arrowMock, contentMock);

            Assert.AreEqual(10, container.PreferredHeight, 10e-9);
        }
Ejemplo n.º 4
0
        public void Draw_NormalSetup_ContentIsDrawn()
        {
            var arrowMock = new GraphicComponentMock();
            var contentMock = new GraphicComponentMock();
            var container = CreateContainer(arrowMock, contentMock);

            container.Draw();

            Assert.True(contentMock.WasDrawn);
        }
Ejemplo n.º 5
0
        public void Draw_NoFixeWidthComponentSizeChanged_LayoutContainerIsNotTriggered()
        {
            var componentMock = new GraphicComponentMock { HorizontalPolicy = ResizePolicy.Extending };
            var container = CreateContainer(componentMock);

            componentMock.RaiseSizeChanged();
            container.Draw();

            layoutMock.Verify(l => l.LayoutContainer(container), Times.Never);
        }
Ejemplo n.º 6
0
        public void Draw_FixedHightComponentSizeChanged_LayoutContainerIsTriggered()
        {
            var componentMock = new GraphicComponentMock { VerticalPolicy = ResizePolicy.Fixed };
            var container = CreateContainer(componentMock);

            componentMock.RaiseSizeChanged();
            container.Draw();

            layoutMock.Verify(l => l.LayoutContainer(container), Times.Once);
        }
Ejemplo n.º 7
0
        public void Draw_PreferredWidthOfAComponentChange_LayoutContainerIsTriggered()
        {
            var componentMock = new GraphicComponentMock { HorizontalPolicy = ResizePolicy.Preferred };
            var container = CreateContainer(componentMock);

            componentMock.RaisePreferredSizeChanged();
            container.Draw();

            layoutMock.Verify(l => l.LayoutContainer(container), Times.Once);
        }
Ejemplo n.º 8
0
        private ItemBox CreateItemBox(IGraphicComponent arrow = null, ITextGraphicComponent text = null)
        {
            if (arrow == null)
                arrow = new GraphicComponentMock();
            if (text == null)
                text = new TextGraphicComponentMock();

            return new ItemBox(arrow, text);

        }
Ejemplo n.º 9
0
        public void Draw_Unselected_ArrowIsNotDrawn()
        {
            var arrowMock = new GraphicComponentMock();
            var contentMock = new GraphicComponentMock();
            var container = CreateContainer(arrowMock, contentMock);

            container.Unselect();
            container.Draw();

            Assert.False(arrowMock.WasDrawn);
        }
Ejemplo n.º 10
0
        public void PreferredHeight_ComponentsPreferredHeightChanged_EqualsContentsNewPreferredHeight()
        {
            var arrowMock = new GraphicComponentMock();
            var contentMock = new GraphicComponentMock();
            var container = CreateContainer(arrowMock, contentMock);

            contentMock.PreferredHeight = 10;
            contentMock.RaisePreferredSizeChanged();

            Assert.AreEqual(10, container.PreferredHeight, 10e-9);
        }
Ejemplo n.º 11
0
        public void Draw_Select_ArrowIsDrawn()
        {
            var arrowMock = new GraphicComponentMock();
            var contentMock = new GraphicComponentMock();
            var container = CreateContainer(arrowMock, contentMock);

            container.Select();
            container.Draw();

            Assert.True(arrowMock.WasDrawn);
        }
Ejemplo n.º 12
0
        public void Draw_NoForeground_NoForegroundDrawn()
        {
            var foregroundComponent = new GraphicComponentMock();
            var testComponent = CreateComponent(foreground: foregroundComponent);
            var batch = new SpriteBatchMock();
            testComponent.SetCoordinates(100, 100, 500, 500);

            testComponent.Foreground = null;
            testComponent.Draw(batch);

            Assert.False(foregroundComponent.WasDrawn);
        }
Ejemplo n.º 13
0
        public void Draw_UnselectedDraw_ArrowNotDrawn(float x, float y, float width, float height)
        {
            SpriteBatchMock spriteBatch = new SpriteBatchMock();
            var arrow = new GraphicComponentMock();
            var textBox = new TextGraphicComponentMock();

            var item = CreateItemBox(arrow, textBox);
            item.SetCoordinates(x, y, width, height);

            item.Draw(spriteBatch);

            Assert.False(arrow.WasDrawn);
        }
Ejemplo n.º 14
0
        public void Update_WithDifferentTimes_GraphicComponentVisibilityIsAsExpected(long time, long animationTime, bool expectedVisibility)
        {
            var animation = CreateAnimation(animationTime);
            var graphicMock = new GraphicComponentMock();
            var startTime = new GameTime();
            var endTime = CreateNextTime(time, startTime);

            animation.Update(startTime, graphicMock);
            animation.Update(endTime, graphicMock);
            graphicMock.Draw();

            Assert.AreEqual(expectedVisibility, graphicMock.IsVisible);
        }
Ejemplo n.º 15
0
        public void Draw_SelectedDraw_ArroLeftOfText(float x, float y, float width, float height)
        {
            SpriteBatchMock spriteBatch = new SpriteBatchMock();
            var arrow = new GraphicComponentMock();
            var textBox = new TextGraphicComponentMock();

            var item = CreateItemBox(arrow, textBox);
            item.SetCoordinates(x, y, width, height);
            item.Select();

            item.Draw(spriteBatch);

            Assert.LessOrEqual(arrow.XPosition, textBox.XPosition);
        }
Ejemplo n.º 16
0
        public static List<GraphicComponentMock> SetupContainer(this Container container, int number, float initialSize = 30.0f)
        {
            var ret = new List<GraphicComponentMock>();

            for(int i = 0; i < number; i++)
            {
                var comp = new GraphicComponentMock();
                comp.Width = initialSize;
                comp.Height = initialSize;
                ret.Add(comp);
                container.AddComponent(comp);
            }

            return ret;
        }
Ejemplo n.º 17
0
        public void Update_WithGivenNumberOfBlinks_BlinksForGivenTimes(long blinkTime, int number)
        {
            var animation = CreateAnimation(blinkTime, number);
            var graphicMock = new GraphicComponentMock();
            var nextTime = new GameTime();
            bool animationFinished = false;
            int numberOfBlinks = 0;
            animation.AnimationFinished += delegate { animationFinished = true; };
            graphicMock.VisibilityChanged += delegate { numberOfBlinks++; };

            while (!animationFinished && numberOfBlinks < 2 * number)
            {
                animation.Update(nextTime, graphicMock);
                nextTime = CreateNextTime(blinkTime, nextTime);
            }

            Assert.True(animationFinished);
            Assert.AreEqual(numberOfBlinks, 2 * number);
        }
Ejemplo n.º 18
0
        //[TestCase(1000)]
        public void Update_NormalUsage_BlinkingTakesGivenTime(long time)
        {
            var animation = CreateAnimation(time);
            var graphicMock = new GraphicComponentMock();
            var startTime = new GameTime();
            var endTime = CreateNextTime(time, startTime);

            animation.Update(startTime, graphicMock);
            graphicMock.Draw();

            Assert.False(graphicMock.WasDrawn);

            animation.Update(endTime, graphicMock);
            graphicMock.Draw();

            Assert.True(graphicMock.WasDrawn);
            
            
        }
Ejemplo n.º 19
0
        public void SetCoordinates_ValidCoordinates_InnerComponentsAreUpdated()
        {
            float x = 100;
            float y = 200;
            float width = 300;
            float height = 400;
            var foregroundComponent = new GraphicComponentMock();
            var backgroundComponent = new GraphicComponentMock();
            var mainComponent = new GraphicComponentMock();

            var testComponent = CreateComponent(mainComponent, backgroundComponent, foregroundComponent);

            testComponent.SetCoordinates(x, y, width, height);

            testComponent.Draw(new SpriteBatchMock());

            AssertCoordinatesEqual(foregroundComponent, testComponent);
            AssertCoordinatesEqual(backgroundComponent, testComponent);
            AssertCoordinatesEqual(mainComponent, testComponent);
        }
Ejemplo n.º 20
0
        public void Draw_AllComponentsSet_RightOrder()
        {
            int drawCounter = 0;
            int foregroundNumber = -1;
            int mainComponentNumber = -1;
            int backgroundNumber = -1;

            var foregroundComponent = new GraphicComponentMock();
            var mainComponent = new GraphicComponentMock();
            var backgroundComponent = new GraphicComponentMock();

            var testComponent = CreateComponent(mainComponent, backgroundComponent, foregroundComponent);
            foregroundComponent.DrawCallback = () => { drawCounter++; foregroundNumber = drawCounter; };
            mainComponent.DrawCallback = () => { drawCounter++; mainComponentNumber = drawCounter; };
            backgroundComponent.DrawCallback = () => { drawCounter++; backgroundNumber = drawCounter; };

            testComponent.Draw(new SpriteBatchMock());

            Assert.AreEqual(1, backgroundNumber);
            Assert.AreEqual(2, mainComponentNumber);
            Assert.AreEqual(3, foregroundNumber);
        }
Ejemplo n.º 21
0
        private MultiLayeredComponent CreateComponent(IGraphicComponent mainComponent = null, IGraphicComponent background = null, IGraphicComponent foreground = null)
        {
            if (mainComponent == null)
                mainComponent = new GraphicComponentMock();
            var testComponent = new MultiLayeredComponent(mainComponent);
            testComponent.Background = background;
            testComponent.Foreground = foreground;

            return testComponent;
        }
Ejemplo n.º 22
0
 private SelectableContainer<GraphicComponentMock> CreateContainer(GraphicComponentMock arrowMock) 
 {
     return CreateContainer(arrowMock, null);
 }
Ejemplo n.º 23
0
        public void Draw_SetContentProperty_ContentIsDrawn()
        {
            var arrowMock = new GraphicComponentMock();
            var contentMock = new GraphicComponentMock();
            var container = CreateContainer(arrowMock);

            container.Content = contentMock;
            container.Draw();

            Assert.True(contentMock.WasDrawn);
            
        }
Ejemplo n.º 24
0
        private Container CreateContainer(GraphicComponentMock componentMock)
        {
            var container = new Container() { Layout = layoutMock.Object};
            container.AddComponent(componentMock);
            container.Draw();
            layoutMock.ResetCalls();

            return container;
        }
Ejemplo n.º 25
0
        protected override IGraphicComponent CreateComponent()
        {
            var mainComponent = new GraphicComponentMock();
            var backgroundComponent = new GraphicComponentMock();
            var foregroundComponent = new GraphicComponentMock();

            return CreateComponent(mainComponent, backgroundComponent, foregroundComponent);
        }
Ejemplo n.º 26
0
        private static Table<GraphicComponentMock> CreateTable(int fieldWidth, int fieldHeight)
        {
            var table = new Table<GraphicComponentMock>();
            for(var i = 0; i < fieldWidth; i++)
                for(var j = 0; j < fieldHeight; j++)
                    table[j, i] = new GraphicComponentMock();

            return table;
        }
Ejemplo n.º 27
0
        private SelectableContainer<GraphicComponentMock> CreateContainer(GraphicComponentMock arrowMock, GraphicComponentMock contentMock)
        {
            SelectableContainer<GraphicComponentMock> container;
            if (contentMock != null)
                container = new SelectableContainer<GraphicComponentMock>(arrowMock, contentMock);
            else
                container = new SelectableContainer<GraphicComponentMock>(arrowMock);

            container.SetCoordinates(10, 10, 100, 100);
            return container;
        }