public void Set_DefectiveComponentCount_Success(uint componentCount) { 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; // Check every month. for (uint i = 0; i < 12; i++) { this.mockPersistentState.Setup(s => s.GetArray <uint>("DefectiveComponentsCount")) .Returns(startingCounts); var newCounts = new uint[12]; startingCounts.CopyTo(newCounts, 0); newCounts[i] = componentCount; defectiveComponentsCounter.SetDefectiveComponentsCount(i, componentCount); this.mockPersistentState.Verify(s => s.SetArray("DefectiveComponentsCount", newCounts), Times.Once); // Clear invocations. this.mockPersistentState.Invocations.Clear(); } }
public void Set_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.SetDefectiveComponentsCount(12, 1)); this.mockPersistentState.Verify(s => s.SetArray("DefectiveComponentsCount", It.IsAny <uint[]>()), Times.Never); }