Started keto with Kristen yesterday. Let's see how this goes!
I think I'll miss noodles most of all, but these fat bombs are hella good.
Started 71.5 inches, 185 pounds, 22.5% body fat according to my scale.
Started keto with Kristen yesterday. Let's see how this goes!
I think I'll miss noodles most of all, but these fat bombs are hella good.
Started 71.5 inches, 185 pounds, 22.5% body fat according to my scale.
// Haven't figured out how to apply to assembly correctly, but added it as a flag in my base anyway [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] public class BaseCategoryAttribute : CategoryAttribute { } public class FastIntegrationTestAttribute : BaseCategoryAttribute { } public class LongRunningIntegrationTestAttribute : BaseCategoryAttribute { } public class UnitTestAttribute : BaseCategoryAttribute { } public class CoreTestAttribute : BaseCategoryAttribute { } [TestFixture, UnitTest, CoreTest] public class SomeClassTests { // This test has categories TestFixture, UnitTest, CoreTest [Test, CoreTest] public void ShouldDoSomething() { } }
public string ReturnNumberAsString(int numberToReturn) { return numberToReturn.ToString(); }
public string ReturnNumberAsString(int numberToReturn) { if (numberToReturn % 3 == 1 && numberToReturn % 5 == 1) return "FizzBuzz"; else if (numberToReturn % 3 == 1) return "Fizz"; else if (numberToReturn % 5 == 1) return "Buzz"; return numberToReturn.ToString(); }
/// <summary> /// number mod 3 and 5 returns FizzBuzz /// number mod 3 returns Fizz /// number mod 5 returns Buzz /// </summary> [TestMethod] public void NumberReturner_ReturnNumberAsString_SpecialCasesReturnValid() { // Arrange NumberReturner rt = new NumberReturner(); int modThree = 9; int modFive = 10; int modThreeAndFive = 15; // Act var resultsModThree = rt.ReturnNumberAsString(modThree); var resultsModFive = rt.ReturnNumberAsString(modFive); var resultsModThreeAndFIve = rt.ReturnNumberAsString(modThreeAndFive); // Assert Assert.AreEqual("Fizz", resultsModThree, nameof(resultsModThree)); Assert.AreEqual("Buzz", resultsModFive, nameof(resultsModFive)); Assert.AreEqual("FizzBuzz", resultsModThreeAndFIve, nameof(resultsModThreeAndFIve)); }
if (numberToReturn % 3 == 1 && numberToReturn % 5 == 1) return "FizzBuzz"; else if (numberToReturn % 3 == 1) return "Fizz"; else if (numberToReturn % 5 == 1) return "Buzz";
if (numberToReturn % 3 == 0 && numberToReturn % 5 == 0) return "FizzBuzz"; else if (numberToReturn % 3 == 0) return "Fizz"; else if (numberToReturn % 5 == 0) return "Buzz";
// Arrange int expected = 42; NumberReturner biz = new NumberReturner(); // Act var results = biz.ReturnNumberAsString(expected); // Assert Assert.AreEqual(expected.ToString(), results);
/// <summary> /// This class is used to return a number. /// </summary> public class NumberReturner { /// <summary> /// Return the provided number as a string /// </summary> /// <param name="numberToReturn">The number to return</param> /// <returns>The number as string</returns> public string ReturnNumberAsString(int numberToReturn) { return numberToReturn.ToString(); } }
/// <summary> /// Tests for NumberReturner /// </summary> [TestClass] public class NumberReturnerTests { /// <summary> /// Ensure ReturnNumberAsString has appropriate return type /// </summary> [TestMethod] public void NumberReturner_ReturnNumberAsString_CorrectReturnTypeIsString() { // Arrange int expected = 42; NumberReturner biz = new NumberReturner(); // Act var results = biz.ReturnNumberAsString(expected); // Assert Assert.IsInstanceOfType(results, typeof(string)); } /// <summary> /// When ReturnNumberAsString is provided a number, the number is returned as a string /// </summary> [TestMethod] public void NumberReturner_ReturnNumberAsString_ReturnsNumberThatWasProvided() { // Arrange int expected = 42; NumberReturner biz = new NumberReturner(); // Act var results = biz.ReturnNumberAsString(expected); // Assert Assert.AreEqual(expected.ToString(), results); } }
namespace RussUnitTestSample
{
class Program
{
#region consts
const string CONNECTION_STRING = "Data Source=192.168.50.4,1515;Initial Catalog=MBES;Persist Security Info=True;Integrated Security=true;";
#endregion consts
#region Entry
static void Main(string[] args)
{
GetNumbersAndAddThem obj = new GetNumbersAndAddThem(
new DbGetSomeNumbers(new BaseDbConnection(CONNECTION_STRING)),
new NumberFunctions()
);
Console.WriteLine("\n");
Console.WriteLine(obj.Execute());
Console.WriteLine("\n");
Business.WCF.Service1 service = new Business.WCF.Service1();
Console.WriteLine("\n");
Console.WriteLine("{0}", service.GetData(42));
Console.WriteLine("\n");
}
#endregion Entry
}
}
namespace RussUnitTestSample.Business.WCF
{
/// <summary>
/// Communication with the WCF Service1
/// </summary>
public class Service1
{
#region Private
private ServiceReference1.Service1Client _service;
#endregion Private
public Service1()
{
this._service = new ServiceReference1.Service1Client();
}
public string GetData(int value)
{
return this._service.GetData(value);
}
}
}
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
namespace RussUnitTestSample.Wcf.Tests
{
/// <summary>
/// Unit tests for service1
/// </summary>
[TestClass]
[ExcludeFromCodeCoverage]
public class Service1Tests
{
/// <summary>
/// Get data works as expected with a positive number
/// </summary>
[TestMethod]
public void Service1_GetData_PositiveNumber()
{
// Arrange
Wcf.Service1 service = new Wcf.Service1();
int num = 55;
var expected = string.Format("You entered: {0}", num);
// Act
var result = service.GetData(num);
// Assert
Assert.AreEqual(expected, result);
}
/// <summary>
/// Get data works as expected with a negative number
/// </summary>
[TestMethod]
public void Service1_GetData_NegativeNumber()
{
// Arrange
Wcf.Service1 service = new Wcf.Service1();
int num = -42;
var expected = string.Format("You entered: {0}", num);
// Act
var result = service.GetData(num);
// Assert
Assert.AreEqual(expected, result);
}
/// <summary>
/// Get data works as expected with zero
/// </summary>
[TestMethod]
public void Service1_GetData_Zero()
{
// Arrange
Wcf.Service1 service = new Wcf.Service1();
int num = 0;
var expected = string.Format("You entered: {0}", num);
// Act
var result = service.GetData(num);
// Assert
Assert.AreEqual(expected, result);
}
/// <summary>
/// An exception is thrown when the CompositeType is null
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Service1_GetDataUsingDataContract_ExceptionThrownWhenCompositeTypeNull()
{
// Arrange
Wcf.Service1 service = new Service1();
// Act
var result = service.GetDataUsingDataContract(null);
}
/// <summary>
/// When BoolValue is false, do not append "Suffix" to StringValue
/// </summary>
[TestMethod]
public void Service1_GetDataUsingDataContract_CompositTypeBoolValueFalse_DoNotAppendSuffix()
{
// Arrange
Wcf.Service1 service = new Service1();
string testString = "Test";
CompositeType ct = new CompositeType()
{
BoolValue = false,
StringValue = testString
};
// Act
var result = service.GetDataUsingDataContract(ct);
// Assert
Assert.AreEqual(testString, result.StringValue);
}
/// <summary>
/// When BoolValue is true, append "Suffix" to StringValue
/// </summary>
[TestMethod]
public void Service1_GetDataUsingDataContract_CompositTypeBoolValueTrue_AppendSuffix()
{
// Arrange
Wcf.Service1 service = new Service1();
string testString = "Test";
CompositeType ct = new CompositeType()
{
BoolValue = true,
StringValue = testString
};
var expected = testString + "Suffix";
// Act
var result = service.GetDataUsingDataContract(ct);
// Assert
Assert.AreEqual(expected, result.StringValue);
}
}
}

namespace RussUnitTestSample.Business.WCF
{
/// <summary>
/// Communication with the WCF Service1
/// </summary>
public class Service1
{
#region Private
private ServiceReference1.Service1Client _service;
#endregion Private
public Service1()
{
this._service = new ServiceReference1.Service1Client();
}
public string GetData(int value)
{
return this._service.GetData(value);
}
}
}
namespace RussUnitTestSample.Business.WCF
{
/// <summary>
/// Communication with the WCF Service1
/// </summary>
public class Service1
{
#region Private
private IService1 _service;
#endregion Private
#region ctor
/// <summary>
/// Constructor - new up IService1 with client
/// </summary>
public Service1()
{
this._service = new Service1Client();
}
/// <summary>
/// Constructor - takes in implementation of IService1
/// </summary>
/// <param name="service">The IService1 implementation
public Service1(IService1 service)
{
if (service == null)
throw new ArgumentNullException(nameof(service));
this._service = service;
}
#endregion ctor
#region Public methods
/// <summary>
/// Call service GetData
/// </summary>
/// <param name="value">The value to pass to the WCF service
/// <returns>The returned value from the WCF service call</returns>
public string GetData(int value)
{
return this._service.GetData(value);
}
#endregion Public methods
}
}
namespace RussUnitTestSample.Business.Tests.WCF
{
/// <summary>
/// Unit tests for Service1
/// </summary>
[TestClass]
[ExcludeFromCodeCoverage]
public class Service1Tests
{
#region Private
private Mock<iservice1> _service;
#endregion Private
#region Public methods
/// <summary>
/// initialize the mocks
/// </summary>
[TestInitialize]
public void Setup()
{
this._service = new Mock<iservice1>();
}
/// <summary>
/// Exception thrown when IService implementation is not provided
/// </summary>
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Service1_NullIService1InConstructor_ThrowsException()
{
// Arrange / Act
Business.WCF.Service1 service = new Business.WCF.Service1(null);
}
/// <summary>
/// Object properly constructed when implementation of IService1 provided
/// </summary>
[TestMethod]
public void Service1_ConstructorWithProvidedIService1_NewsCorrectly()
{
// Arrange / Act
Business.WCF.Service1 service = new Business.WCF.Service1(_service.Object);
// Assert
Assert.IsInstanceOfType(service, typeof(Business.WCF.Service1));
}
/// <summary>
/// Ensure that a string is returned from Service1 when calling GetData
/// </summary>
[TestMethod]
public void Service1_GetDataTest()
{
// Arrange
this._service.Setup(s => s.GetData(It.IsAny<int>())).Returns("test");
Business.WCF.Service1 service = new Business.WCF.Service1(_service.Object);
// Act
var result = service.GetData(It.IsAny<int>());
// Assert
Assert.IsInstanceOfType(result, typeof(string));
}
#endregion Public methods
}
}












<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:23336/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
Now our service reference is all added and ready, let’s test it! Modify the Program.CS of the console application with:ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
Console.WriteLine("\n");
Console.WriteLine("{0}", client.GetData(42));
Console.WriteLine("\n");
namespace RussUnitTestSample
{
class Program
{
#region consts
const string CONNECTION_STRING = "Data Source=192.168.50.4,1515;Initial Catalog=MBES;Persist Security Info=True;Integrated Security=true;";
#endregion consts
#region Entry
static void Main(string[] args)
{
GetNumbersAndAddThem obj = new GetNumbersAndAddThem(
new DbGetSomeNumbers(new BaseDbConnection(CONNECTION_STRING)),
new NumberFunctions()
);
Console.WriteLine("\n");
Console.WriteLine(obj.Execute());
Console.WriteLine("\n");
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
Console.WriteLine("\n");
Console.WriteLine("{0}", client.GetData(42));
Console.WriteLine("\n");
}
#endregion Entry
}
}
Give it a run and: