public void ComputeTotal_Fails_Sender_Not_Manufacturer() { 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.mockContractState.Setup(s => s.Message.Sender).Returns(Address.Zero); Assert.Throws <SmartContractAssertException>(() => defectiveComponentsCounter.ComputeTotal()); }
[InlineData(new uint[] { 1, uint.MaxValue })] // 1, uint.MaxValue public void ComputeTotal_Overflow_Throws_Exception(uint[] components) { components = ToFixedWidthArray(components); 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.Setup(s => s.GetArray <uint>("DefectiveComponentsCount")).Returns(components); Assert.Throws <OverflowException>(() => defectiveComponentsCounter.ComputeTotal()); }
public void ComputeTotal_Computes_Correctly(uint[] components, uint expectedTotal) { components = ToFixedWidthArray(components); 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, ToByteArray(components)); this.mockPersistentState.Setup(s => s.GetArray <uint>("DefectiveComponentsCount")).Returns(components); defectiveComponentsCounter.ComputeTotal(); this.mockPersistentState.Verify(s => s.SetUInt32(nameof(DefectiveComponentCounter.Total), expectedTotal)); }