Nethereum / Nethereum.Contracts.IntegrationTester

Nethereum.Contracts.IntegrationTester
MIT License
1 stars 2 forks source link

Add Get events and FirstEvent extensions #8

Open juanfranblanco opened 6 years ago

juanfranblanco commented 6 years ago
public static class TransactionResultExtensions
    {
        public static TEventDTO GetFirstEventOutput<TEventDTO>(this TransactionResult transactionResult) where TEventDTO : new()
        {
            //transactionResult.TestLogger.LogExpectedEvent(expectedEvent);

            var eventItem = transactionResult.ContractHandler.GetEvent<TEventDTO>();
            var eventFirst = eventItem.DecodeAllEventsForEvent<TEventDTO>(transactionResult.TransactionReceipt.Logs).FirstOrDefault();

            transactionResult.TestLogger.LogExpectedEvent(eventFirst);

            return eventFirst.Event;
        }

    }
juanfranblanco commented 6 years ago

Assert expectations should exclude some fields generated.

juanfranblanco commented 6 years ago

Maybe expose the asserter or just pass the filter to simplify user usage.

Asserter assert = TestHelper.CreateShortAsserter(); assert.Project.Include(x => x.Name);

https://github.com/kbilsted/StatePrinter/blob/master/doc/AutomatingUnitTesting.md#62-restricting-fields-harvested

var state = new A { X = DateTime.Now, Name = "Charly" }; assert.PrintEquals("new A(){ Name = ""Charly""}", state);