You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Sandeep <Sa...@indatus.com> on 2010/05/25 15:40:11 UTC

Nunit Testing & Cassandra

Hi all,

I am recent grad and working on  Cassandra and Nunit testing.

I wrote a unit test in C# which goes like this

List<KeySlice> listOfKeys = new List<KeySlice>();

            KeySlice item1 = new KeySlice();

            KeySlice item2 = new KeySlice();

            KeySlice item3 = new KeySlice();

            KeySlice item4 = new KeySlice();

            item1.Key = "key1";

            item2.Key = "key2";

            item3.Key = "key3";

            item4.Key = "key4";

            List<ColumnOrSuperColumn> listOfColumnOrSuperColumn1 = new List<ColumnOrSuperColumn>();

            List<ColumnOrSuperColumn> listOfColumnOrSuperColumn2 = new List<ColumnOrSuperColumn>();

            List<ColumnOrSuperColumn> listOfColumnOrSuperColumn3 = new List<ColumnOrSuperColumn>();

            List<ColumnOrSuperColumn> listOfColumnOrSuperColumn4 = new List<ColumnOrSuperColumn>();

            listOfColumnOrSuperColumn1.Add(new ColumnOrSuperColumn() { Column = new Column() { Name = utf8Encoding.GetBytes("key1"), Value = utf8Encoding.GetBytes("100"), Timestamp = timeStamp } });

            listOfColumnOrSuperColumn2.Add(new ColumnOrSuperColumn() { Column = new Column() { Name = utf8Encoding.GetBytes("key2"), Value = utf8Encoding.GetBytes("200"), Timestamp = timeStamp } });

            listOfColumnOrSuperColumn3.Add(new ColumnOrSuperColumn() { Column = new Column() { Name = utf8Encoding.GetBytes("key3"), Value = utf8Encoding.GetBytes("300"), Timestamp = timeStamp } });

            listOfColumnOrSuperColumn4.Add(new ColumnOrSuperColumn() { Column = new Column() { Name = utf8Encoding.GetBytes("key4"), Value = utf8Encoding.GetBytes("400"), Timestamp = timeStamp } });

            item1.Columns = listOfColumnOrSuperColumn1;

            item2.Columns = listOfColumnOrSuperColumn2;

            item3.Columns = listOfColumnOrSuperColumn3;

            item4.Columns = listOfColumnOrSuperColumn4;

            listOfKeys.Add(item1);

            listOfKeys.Add(item3);

            listOfKeys.Add(item4);

            listOfKeys.Add(item2);

            Assert.AreEqual(listOfKeys,  Is.EquivalentTo(TestService.GetListOfRowKeysFromCF("ColumnFamilyName","Keyspace1")));

            TestService.GetListOfRowKeysFromCF() returns a List<Keyslices>. I am constructing the same list<Keyslices> in the same order in which I have inserted in some other method.

            But the test always fails. Can any one please tell me where am I going wrong. Timestamp value is a global variable and is used through out the class.

      Thanks in advance.

RE: Nunit Testing & Cassandra

Posted by Sandeep <Sa...@indatus.com>.
SDSWebService.Service1Test.GetListOfRowKeysFromCF:
  Expected: equivalent to < <KeySlice(key: key1,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])>, <KeySlice(key: key3,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])>, <KeySlice(key: key4,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])>, <KeySlice(key: key2,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])> >

  But was:  < <KeySlice(key: key1,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])>, <KeySlice(key: key3,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])>, <KeySlice(key: key4,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])>, <KeySlice(key: key2,columns: System.Collections.Generic.List`1[Apache.Cassandra.ColumnOrSuperColumn])> >

Is.EquivalentTo( ICollection ) ----- tests that two collections are equivalent.

Two collections are equivalent if they contain the same items, in any order.

Assert.That(listOfKeys,  Is.EquivalentTo(TestService.GetListOfRowKeysFromCF("ColumnFamilyName","Keyspace1")));

From: Miguel Verde [mailto:miguelitovert@gmail.com]
Sent: Tuesday, May 25, 2010 9:51 AM
To: user@cassandra.apache.org
Subject: Re: Nunit Testing & Cassandra

It would be helpful to know in what way the test fails, or more information about listOfKeys or the return value of GetListOfRowKeysFromCF at assert time, or for that matter what GetListOfRowKeysFromCF is, or the insertion code.

Also, does Is.EquivalentTo compare object equality on the items inside the collection? If so, that would be a problem.
On Tue, May 25, 2010 at 8:40 AM, Sandeep <Sa...@indatus.com>> wrote:
            Assert.AreEqual(listOfKeys,  Is.EquivalentTo(TestService.GetListOfRowKeysFromCF("ColumnFamilyName","Keyspace1")));

            TestService.GetListOfRowKeysFromCF() returns a List<Keyslices>. I am constructing the same list<Keyslices> in the same order in which I have inserted in some other method.

            But the test always fails. Can any one please tell me where am I going wrong. Timestamp value is a global variable and is used through out the class.

      Thanks in advance.


Re: Nunit Testing & Cassandra

Posted by Miguel Verde <mi...@gmail.com>.
It would be helpful to know in what way the test fails, or more information
about listOfKeys or the return value of GetListOfRowKeysFromCF at assert
time, or for that matter what GetListOfRowKeysFromCF is, or the insertion
code.

Also, does Is.EquivalentTo compare object equality on the items inside the
collection? If so, that would be a problem.

On Tue, May 25, 2010 at 8:40 AM, Sandeep <Sa...@indatus.com> wrote:

>              Assert.AreEqual(listOfKeys,  Is
> .EquivalentTo(TestService.GetListOfRowKeysFromCF("ColumnFamilyName",
> "Keyspace1")));
>
>
>
>             TestService.GetListOfRowKeysFromCF() returns a List<Keyslices>.
> I am constructing the same list<Keyslices> in the same order in which I have
> inserted in some other method.
>
>
>
>             But the test always fails. Can any one please tell me where am
> I going wrong. Timestamp value is a global variable and is used through out
> the class.
>
>
>
>       Thanks in advance.
>