Skip to content

Commit

Permalink
Increase Test Coverage [API-2264] (#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
emreyigit authored Oct 8, 2024
1 parent 9f0f300 commit 2a5e1ec
Show file tree
Hide file tree
Showing 18 changed files with 1,607 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace Hazelcast.Tests.Models
{
using NUnit.Framework;
using Hazelcast.Models;
using Hazelcast.Core;
using Hazelcast.Serialization;

[TestFixture]
public class CacheSimpleEntryListenerOptionsTests
{
[Test]
public void DefaultConstructor_SetsPropertiesToDefault()
{
var options = new CacheSimpleEntryListenerOptions();

Assert.IsNull(options.CacheEntryListenerFactory);
Assert.IsNull(options.CacheEntryEventFilterFactory);
Assert.IsFalse(options.OldValueRequired);
Assert.IsFalse(options.Synchronous);
}

[Test]
public void Constructor_WithCacheSimpleEntryListenerOptionsArgument_CopiesProperties()
{
var originalOptions = new CacheSimpleEntryListenerOptions
{
CacheEntryListenerFactory = "TestFactory",
CacheEntryEventFilterFactory = "TestFilterFactory",
OldValueRequired = true,
Synchronous = true
};
var copiedOptions = new CacheSimpleEntryListenerOptions(originalOptions);

Assert.AreEqual(originalOptions.CacheEntryListenerFactory, copiedOptions.CacheEntryListenerFactory);
Assert.AreEqual(originalOptions.CacheEntryEventFilterFactory, copiedOptions.CacheEntryEventFilterFactory);
Assert.AreEqual(originalOptions.OldValueRequired, copiedOptions.OldValueRequired);
Assert.AreEqual(originalOptions.Synchronous, copiedOptions.Synchronous);
}

[Test]
public void ToString_ReturnsExpectedFormat()
{
var options = new CacheSimpleEntryListenerOptions
{
CacheEntryListenerFactory = "TestFactory",
CacheEntryEventFilterFactory = "TestFilterFactory",
OldValueRequired = true,
Synchronous = true
};

var result = options.ToString();

StringAssert.Contains("cacheEntryListenerFactory='TestFactory'", result);
StringAssert.Contains("cacheEntryEventFilterFactory='TestFilterFactory'", result);
StringAssert.Contains("oldValueRequired=True", result);
StringAssert.Contains("synchronous=True", result);
}
}
}
80 changes: 80 additions & 0 deletions src/Hazelcast.Net.Tests/Models/DataPersistenceOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Hazelcast.Core;
using NUnit.Framework;
using Hazelcast.Models;
using Hazelcast.Serialization;
using NSubstitute;
namespace Hazelcast.Tests.Models
{
[TestFixture]
public class DataPersistenceOptionsTests
{
[Test]
public void Constructor_WithValidParameters_InitializesPropertiesCorrectly()
{
var enabled = true;
var fsync = true;

var dataPersistenceOptions = new DataPersistenceOptions
{
Enabled = enabled,
Fsync = fsync
};

Assert.AreEqual(enabled, dataPersistenceOptions.Enabled);
Assert.AreEqual(fsync, dataPersistenceOptions.Fsync);
}

[Test]
public void WriteData_ReadData_WritesAndReadsDataCorrectly()
{
var enabled = true;
var fsync = true;

var dataPersistenceOptions = new DataPersistenceOptions
{
Enabled = enabled,
Fsync = fsync
};

var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian);
dataPersistenceOptions.WriteData(output);

var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian);
var readDataPersistenceOptions = new DataPersistenceOptions();
readDataPersistenceOptions.ReadData(input);

Assert.AreEqual(dataPersistenceOptions.Enabled, readDataPersistenceOptions.Enabled);
Assert.AreEqual(dataPersistenceOptions.Fsync, readDataPersistenceOptions.Fsync);
}

[Test]
public void ToString_ReturnsCorrectFormat()
{
var enabled = true;
var fsync = true;

var dataPersistenceOptions = new DataPersistenceOptions
{
Enabled = enabled,
Fsync = fsync
};

var expectedString = $"DataPersistenceConfig{{enabled={enabled}, fsync={fsync}}}";

Assert.AreEqual(expectedString, dataPersistenceOptions.ToString());
}
}
}
66 changes: 66 additions & 0 deletions src/Hazelcast.Net.Tests/Models/DiskTierOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Hazelcast.Core;
using NUnit.Framework;
using Hazelcast.Models;
using Hazelcast.Serialization;
using NSubstitute;
namespace Hazelcast.Tests.Models
{
[TestFixture]
public class DiskTierOptionsTests
{
[Test]
public void Constructor_WithValidParameters_InitializesPropertiesCorrectly()
{
var enabled = true;
var deviceName = "TestDevice";

var diskTierOptions = new DiskTierOptions { Enabled = enabled, DeviceName = deviceName };

Assert.AreEqual(enabled, diskTierOptions.Enabled);
Assert.AreEqual(deviceName, diskTierOptions.DeviceName);
}

[Test]
public void WriteData_ReadData_WritesAndReadsDataCorrectly()
{
var enabled = true;
var deviceName = "TestDevice";
var diskTierOptions = new DiskTierOptions { Enabled = enabled, DeviceName = deviceName };

var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian);
diskTierOptions.WriteData(output);

var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian);
var readDiskTierOptions = new DiskTierOptions();
readDiskTierOptions.ReadData(input);

Assert.AreEqual(diskTierOptions.Enabled, readDiskTierOptions.Enabled);
Assert.AreEqual(diskTierOptions.DeviceName, readDiskTierOptions.DeviceName);
}

[Test]
public void ToString_ReturnsCorrectFormat()
{
var enabled = true;
var deviceName = "TestDevice";
var diskTierOptions = new DiskTierOptions { Enabled = enabled, DeviceName = deviceName };

var expectedString = $"DiskTierConfig{{enabled={enabled}, deviceName='{deviceName}'}}";

Assert.AreEqual(expectedString, diskTierOptions.ToString());
}
}
}
80 changes: 80 additions & 0 deletions src/Hazelcast.Net.Tests/Models/HotRestartOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using Hazelcast.Core;
using NUnit.Framework;
using Hazelcast.Models;
using Hazelcast.Serialization;
using NSubstitute;
namespace Hazelcast.Tests.Models
{
[TestFixture]
public class HotRestartOptionsTests
{
[Test]
public void Constructor_WithValidParameters_InitializesPropertiesCorrectly()
{
var enabled = true;
var fsync = true;

var hotRestartOptions = new HotRestartOptions
{
Enabled = enabled,
Fsync = fsync
};

Assert.AreEqual(enabled, hotRestartOptions.Enabled);
Assert.AreEqual(fsync, hotRestartOptions.Fsync);
}

[Test]
public void WriteData_ReadData_WritesAndReadsDataCorrectly()
{
var enabled = true;
var fsync = true;

var hotRestartOptions = new HotRestartOptions
{
Enabled = enabled,
Fsync = fsync
};

var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian);
hotRestartOptions.WriteData(output);

var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian);
var readHotRestartOptions = new HotRestartOptions();
readHotRestartOptions.ReadData(input);

Assert.AreEqual(hotRestartOptions.Enabled, readHotRestartOptions.Enabled);
Assert.AreEqual(hotRestartOptions.Fsync, readHotRestartOptions.Fsync);
}

[Test]
public void ToString_ReturnsCorrectFormat()
{
var enabled = true;
var fsync = true;

var hotRestartOptions = new HotRestartOptions
{
Enabled = enabled,
Fsync = fsync
};

var expectedString = $"HotRestartConfig{{enabled={enabled}, fsync={fsync}}}";

Assert.AreEqual(expectedString, hotRestartOptions.ToString());
}
}
}
Loading

0 comments on commit 2a5e1ec

Please sign in to comment.