示例#1
0
        private static CellStatusManager CreateCellStatusManager(CellStatusType currentStatus)
        {
            CellStatusManager componentForTest = new();

            PropertyInfo?currentStatusProperty = typeof(CellStatusManager).GetProperty(nameof(CellStatusManager.CurrentStatus));

            currentStatusProperty !.SetValue(componentForTest, currentStatus, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);

            return(componentForTest);
        }
示例#2
0
        public void MoveNext_MoveToUndefinedStatus_Throws(CellStatusType currentStatus, CellInteractionType command, bool?isMine)
        {
            // Arrange
            CellStatusManager componentUnderTest = CreateCellStatusManager(currentStatus);

            // Act && Assert
            Action testAction = () => componentUnderTest.MoveNext(command, isMine);

            testAction.Should().Throw <InvalidOperationException>();
        }
示例#3
0
        public void CanMoveNext_DefinedTransition_ReturnsTrue(CellStatusType currentStatus, CellInteractionType command, bool?isMine)
        {
            // Arrange
            CellStatusManager componentUnderTest = CreateCellStatusManager(currentStatus);

            // Act
            bool result = componentUnderTest.CanMoveNext(command, isMine);

            // Assert
            result.Should().BeTrue();
        }
示例#4
0
        public void MoveNext_DefinedTransition_ReturnsNextStatus(CellStatusType currentStatus, CellInteractionType command, bool?isMine, CellStatusType expectedNextStatus)
        {
            // Arrange
            CellStatusManager componentUnderTest = CreateCellStatusManager(currentStatus);

            // Act
            CellStatusType result = componentUnderTest.MoveNext(command, isMine);

            // Assert
            result.Should().Be(expectedNextStatus);
        }
示例#5
0
        public CellVisualization GetVisualization(CellStatusType cellStatus, byte?adjacentMineCount)
        {
            (char?content, string cssClass)template = GetVisualizationTemplateOrDefault(cellStatus);

            string cssClass = String.Format(CultureInfo.InvariantCulture, template.cssClass, adjacentMineCount);

            if (template.content is null && adjacentMineCount is null)
            {
                throw new ArgumentNullException(nameof(adjacentMineCount));
            }

            char content = template.content ?? GetAdjacentMineCountContent(adjacentMineCount !.Value);

            return(new(content, cssClass));
        }
 internal CellStatusManager()
 {
     CurrentStatus = CellStatusType.Covered;
     transitions   = new Dictionary <CellStatusTransition, CellStatusType>
     {
         { new CellStatusTransition(CellStatusType.Covered, new (CellInteractionType.LeftClick, false)), CellStatusType.Uncovered },
 public CellStatusTransition(CellStatusType processState, CellStatusTransitionCommand command)
 {
     this.processState = processState;
     this.command      = command;
 }
示例#8
0
 public CellVisualization GetVisualization(CellStatusType cellStatus) => GetVisualization(cellStatus, null);