Beispiel #1
0
        public void Get_DefectiveComponentCount_Success()
        {
            this.mockPersistentState.Setup(s => s.GetAddress(nameof(DefectiveComponentCounter.Manufacturer))).Returns(ManufacturerAddress);
            this.mockContractState.Setup(s => s.Message.Sender).Returns(ManufacturerAddress);

            var defectiveComponentsCounter = new DefectiveComponentCounter(this.mockContractState.Object, new byte[] { });

            var startingCounts = new uint[12]
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
            };

            this.mockPersistentState.Setup(s => s.GetArray <uint>("DefectiveComponentsCount"))
            .Returns(startingCounts);

            // Check every month.
            for (uint i = 0; i < 12; i++)
            {
                Assert.Equal(startingCounts[i], defectiveComponentsCounter.GetDefectiveComponentsCount(i));

                this.mockPersistentState.Verify(s => s.GetArray <uint>("DefectiveComponentsCount"), Times.Once);

                // Clear invocations.
                this.mockPersistentState.Invocations.Clear();
            }
        }
Beispiel #2
0
        public void Get_DefectiveComponentCount_Failure_If_12()
        {
            this.mockPersistentState.Setup(s => s.GetAddress(nameof(DefectiveComponentCounter.Manufacturer))).Returns(ManufacturerAddress);
            this.mockContractState.Setup(s => s.Message.Sender).Returns(ManufacturerAddress);

            var defectiveComponentsCounter = new DefectiveComponentCounter(this.mockContractState.Object, new byte[] { });

            this.mockPersistentState.Invocations.Clear();

            Assert.Throws <SmartContractAssertException>(() => defectiveComponentsCounter.GetDefectiveComponentsCount(12));

            this.mockPersistentState.Verify(s => s.GetArray <uint>("DefectiveComponentsCount"), Times.Never);
        }