Click here to Skip to main content
15,885,947 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am new to unit testing, please help me with writing correct unit tests for below method.

Functionality: It just calls one method internally & get the object, based on object value returns true/ false.

public bool IsItemLevelDiscountEnabledInStore()
       {
           var discountConfig = GetDiscountConfigDetails();
           if (discountConfig.ItemDiscount.enabled)
           {
               return true;
           }

           return false;
       }


What I have tried:

[Theory]
        [InlineData(true)]
        [InlineData(false)]
        public void ItemLevelDiscountEnabledInStoreDb(bool value)
        {
            //Arrange
         
            var discountConfig = new DiscountConfig
            {
                ItemDiscount = new ItemDiscount
                {
                    enabled = value
                }
            };
            _discountServiceMock.Setup(x => x.GetDiscountConfigDetails()).Returns(discountConfig);

            //Act
          

            //Assert
        
        }
Posted
Updated 27-Oct-22 11:32am
v2
Comments
PIEBALDconsult 27-Oct-22 8:59am    
If it made sense to do so, you would already know how.
Virendra S from Bangalore, Karnataka 27-Oct-22 9:21am    
Okay, you can ignore my test, could you please suggest one?

1 solution

Google search is your friend.
1. NUnit: nunit bool check - Google Search[^] finds this: Assert.True | NUnit Docs[^]


2. XUnit: xunit bool check - Google Search[^] finds this: Xunit.Assert.Equal(bool, bool) Example[^]

For XUnit, I like using: >Fluent Assertions - Fluent Assertions[^] and here is testing bools: Booleans - Fluent Assertions[^]
 
Share this answer
 
Comments
Virendra S from Bangalore, Karnataka 29-Oct-22 16:29pm    
Thanks Graeme_Grant
Graeme_Grant 29-Oct-22 22:56pm    
If this helped, please mark it as accepted so that others who read this know it was helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900