I'm trying to write a unit test for one of the stored procedures. In the model I'm passing it as a list of guid later on to the stored procedure I'm serializing it because SQL doesn't accept a list of GUID.
I'm kind of confused about how I should initialize it for the unit test, data on stored procedure
IEnumerable<Guid> aOfferId
This is the stored procedure class:
{
[Schema(SqlSchema.Offer)]
public class testO : StoredProcedure<int>
{
public testO(Guid tId,IEnumerable<Guid>OfferId, Guid userId)
{
TID = tId;
AdvertOfferId =JsonConvert.SerializeObject(advertOfferId);
PUserId = userId;
}
public override Task<int> RunAsync() => ExecuteAsync();
}
}
AdvertOfferId = JsonConvert.SerializeObject(advertOfferId);
{
using System;
s;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
[TestClass]
public class testOTests
{
[TestMethod]
public void NonNullTests()
{
// var advertOfferSerialize= JsonConvert.SerializeObject(advertOfferId);
var sproc = new testO(tId, aId, userId);
Assert.AreEqual(aId, sproc.AId);
}
}
}
My test fails if I initialize data like the above.
CodePudding user response:
If you ask me, this is how it should work:
using System;
using System.Collections.Generic;
using CCE.Core.Models.SQL.Schemas.Offer.StoredProcedures;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
namespace CCE.Offers.UnitTests.SQL.StoredProcedure
{
[TestClass]
public class ArchiveCpgOfferTests
{
[TestMethod]
public void NonNullTests()
{
//arrange
var tenantId = Guid.Empty;
var portalUserId = Guid.Empty;
var advertOfferId = new List<Guid> { Guid.NewGuid() };
var advertOfferSerialized = JsonConvert.SerializeObject(advertOfferId);
//act
var sproc = new ArchiveCpgOffer(tenantId, advertOfferId, portalUserId);
//assert
Assert.AreEqual(advertOfferSerialized, sproc.AdvertOfferId);
//this assertion does not make sense, it's always true:
//Assert.IsNotNull(sproc);
}
}
}
I'm not sure how useful your scenario is, but this way it should compile and run.