Fix unit tests
This commit is contained in:
Родитель
cc290ca5f9
Коммит
aec104fe07
|
@ -23,7 +23,7 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
var mockDevice = new Mock<Device>();
|
||||
|
||||
PageLog emptyLog = new PageLog();
|
||||
PageLog log = new PageLog(Timestamp, mockDevice.Object, Name);
|
||||
PageLog log = new PageLog(mockDevice.Object, Name, Timestamp);
|
||||
|
||||
Assert.IsNotNull(emptyLog);
|
||||
Assert.IsNotNull(log);
|
||||
|
@ -40,7 +40,7 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
const string NullName = null;
|
||||
var mockDevice = new Mock<Device>();
|
||||
|
||||
PageLog log = new PageLog(Timestamp, mockDevice.Object, NullName);
|
||||
PageLog log = new PageLog(mockDevice.Object, NullName, Timestamp);
|
||||
Assert.ThrowsException<ValidationException>(() => log.Validate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
var mockDevice = new Mock<Device>();
|
||||
|
||||
StartSessionLog emptyLog = new StartSessionLog();
|
||||
StartSessionLog log = new StartSessionLog(Timestamp, mockDevice.Object);
|
||||
StartSessionLog log = new StartSessionLog(mockDevice.Object, Timestamp);
|
||||
|
||||
Assert.IsNotNull(emptyLog);
|
||||
Assert.IsNotNull(log);
|
||||
|
|
|
@ -515,7 +515,7 @@ namespace Microsoft.AppCenter.Test
|
|||
var properties = new CustomProperties();
|
||||
properties.Set("test", "test");
|
||||
AppCenter.SetCustomProperties(properties);
|
||||
channelUnitMock.Verify(channel => channel.EnqueueAsync(It.Is<CustomPropertiesLog>(log =>
|
||||
channelUnitMock.Verify(channel => channel.EnqueueAsync(It.Is<CustomPropertyLog>(log =>
|
||||
log.Properties == properties.Properties)), Times.Once());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Linq;
|
||||
using Microsoft.AppCenter.Ingestion.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AppCenter.Test.Windows
|
||||
{
|
||||
|
@ -144,7 +147,7 @@ namespace Microsoft.AppCenter.Test.Windows
|
|||
var normalValue = "test";
|
||||
properties.Set(key, normalValue);
|
||||
Assert.AreEqual(1, properties.Properties.Count);
|
||||
Assert.AreEqual(normalValue, properties.Properties[key]);
|
||||
FindProperty(properties.Properties, key, normalValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -161,7 +164,7 @@ namespace Microsoft.AppCenter.Test.Windows
|
|||
var normalValue = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
properties.Set(key, normalValue);
|
||||
Assert.AreEqual(1, properties.Properties.Count);
|
||||
Assert.AreEqual(normalValue, properties.Properties[key]);
|
||||
FindProperty(properties.Properties, key, normalValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -185,15 +188,15 @@ namespace Microsoft.AppCenter.Test.Windows
|
|||
properties.Set("t4", value4);
|
||||
properties.Set("t5", value5);
|
||||
Assert.AreEqual(5, properties.Properties.Count);
|
||||
Assert.AreEqual(value1, properties.Properties["t1"]);
|
||||
Assert.AreEqual(value2, properties.Properties["t2"]);
|
||||
Assert.AreEqual(value3, properties.Properties["t3"]);
|
||||
Assert.AreEqual(value4, properties.Properties["t4"]);
|
||||
Assert.AreEqual(value5, properties.Properties["t5"]);
|
||||
FindProperty(properties.Properties, "t1", value1);
|
||||
FindProperty(properties.Properties, "t2", value2);
|
||||
FindProperty(properties.Properties, "t3", value3);
|
||||
FindProperty(properties.Properties, "t4", value4);
|
||||
FindProperty(properties.Properties, "t5", value5);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that bool setting correct.
|
||||
/// Verify that bool setting correc
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestSetBool()
|
||||
|
@ -206,7 +209,7 @@ namespace Microsoft.AppCenter.Test.Windows
|
|||
var normalValue = false;
|
||||
properties.Set(key, normalValue);
|
||||
Assert.AreEqual(1, properties.Properties.Count);
|
||||
Assert.AreEqual(normalValue, properties.Properties[key]);
|
||||
FindProperty(properties.Properties, key, normalValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -220,7 +223,22 @@ namespace Microsoft.AppCenter.Test.Windows
|
|||
Assert.AreEqual(0, properties.Properties.Count);
|
||||
properties.Clear(key);
|
||||
Assert.AreEqual(1, properties.Properties.Count);
|
||||
Assert.IsNull(properties.Properties[key]);
|
||||
FindProperty(properties.Properties, key, null);
|
||||
}
|
||||
|
||||
private static void FindProperty(IList<CustomProperty> properties, string key, object value)
|
||||
{
|
||||
CustomProperty compareProperty = null;
|
||||
foreach (var elt in properties)
|
||||
{
|
||||
if (elt.Name == key)
|
||||
{
|
||||
compareProperty = elt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull(compareProperty);
|
||||
Assert.AreEqual(value, compareProperty.GetValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
{
|
||||
new StringProperty("t1", "test"),
|
||||
new DateTimeProperty("t2", new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)),
|
||||
new NumberProperty("t3", 1),
|
||||
new NumberProperty("t4", 0.1f),
|
||||
new NumberProperty("t3", (long)1),
|
||||
new NumberProperty("t4", 0.1),
|
||||
new BooleanProperty("t5", false),
|
||||
new ClearProperty("t6")
|
||||
},
|
||||
|
@ -64,26 +64,10 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
{
|
||||
var retrievedProperty = GetPropertyWithName(retrievedLog.Properties, addedProperty.Name);
|
||||
Assert.IsNotNull(retrievedProperty);
|
||||
Assert.IsTrue(EqualityComparer<object>.Default.Equals(addedProperty.GetValue(), retrievedProperty.GetValue()));
|
||||
Assert.AreEqual(addedProperty.GetValue(), retrievedProperty.GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate that log is not valid with nullable 'Properties'
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void ValidateStartServiceLog()
|
||||
{
|
||||
var log = new CustomPropertyLog
|
||||
{
|
||||
Properties = null,
|
||||
Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(),
|
||||
Timestamp = DateTime.Now
|
||||
};
|
||||
|
||||
Assert.ThrowsException<ValidationException>((Action)log.Validate);
|
||||
}
|
||||
|
||||
private static CustomProperty GetPropertyWithName(IList<CustomProperty> properties, string name)
|
||||
{
|
||||
foreach (var property in properties)
|
||||
|
|
|
@ -28,8 +28,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
{
|
||||
const string deafultString = default(string);
|
||||
var emptyDevice = new Device();
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = SdkVersion,
|
||||
OsName = OsName,
|
||||
OsVersion = OsVersion,
|
||||
Locale = Locale,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = AppVersion,
|
||||
AppBuild = AppBuild,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
Assert.IsNotNull(emptyDevice);
|
||||
Assert.IsNotNull(device);
|
||||
|
||||
|
@ -63,8 +75,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateSuccessfullWhenAllFieldsArePresent()
|
||||
{
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = SdkVersion,
|
||||
OsName = OsName,
|
||||
OsVersion = OsVersion,
|
||||
Locale = Locale,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = AppVersion,
|
||||
AppBuild = AppBuild,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
device.Validate();
|
||||
}
|
||||
|
||||
|
@ -74,8 +98,7 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenSdkNameIsNull()
|
||||
{
|
||||
const string nullSdkName = null;
|
||||
var device = new Device(nullSdkName, SdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
var device = new Device(null, SdkVersion, OsName, OsVersion, Locale, TimeZoneOffset, AppVersion, AppBuild, null, null, Model);
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
|
@ -85,30 +108,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenSdkVersionIsNull()
|
||||
{
|
||||
const string nullSdkVersion = null;
|
||||
var device = new Device(SdkName, nullSdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that Validate method throws ValidationException when model == null.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenModelIsNull()
|
||||
{
|
||||
const string nullModel = null;
|
||||
var device = new Device(SdkName, SdkVersion, nullModel, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that Validate method throws ValidationException when oemName == null.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenOemNameIsNull()
|
||||
{
|
||||
const string nullOemName = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, nullOemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = null,
|
||||
OsName = OsName,
|
||||
OsVersion = OsVersion,
|
||||
Locale = Locale,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = AppVersion,
|
||||
AppBuild = AppBuild,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
|
@ -118,8 +131,7 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenOsNameIsNull()
|
||||
{
|
||||
const string nullOsName = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, nullOsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
var device = new Device(SdkName, SdkVersion, null, OsVersion, Locale, TimeZoneOffset, AppVersion, AppBuild, null, null, Model, OemName);
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
|
@ -129,8 +141,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenOsVersionIsNull()
|
||||
{
|
||||
const string nullOsVersion = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, nullOsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = SdkVersion,
|
||||
OsName = OsName,
|
||||
OsVersion = null,
|
||||
Locale = Locale,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = AppVersion,
|
||||
AppBuild = AppBuild,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
|
@ -140,19 +164,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenLocaleIsNull()
|
||||
{
|
||||
const string nullLocale = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, OsVersion, nullLocale, TimeZoneOffset, ScreenSize, AppVersion, AppBuild);
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that Validate method throws ValidationException when screenSize == null.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenScreenSizeIsNull()
|
||||
{
|
||||
const string nullScreenSize = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, nullScreenSize, AppVersion, AppBuild);
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = SdkVersion,
|
||||
OsName = OsName,
|
||||
OsVersion = OsVersion,
|
||||
Locale = null,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = AppVersion,
|
||||
AppBuild = AppBuild,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
|
@ -162,8 +187,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenAppVersionIsNull()
|
||||
{
|
||||
const string nullAppVersion = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, nullAppVersion, AppBuild);
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = SdkVersion,
|
||||
OsName = OsName,
|
||||
OsVersion = OsVersion,
|
||||
Locale = Locale,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = null,
|
||||
AppBuild = AppBuild,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
|
||||
|
@ -173,8 +210,20 @@ namespace Microsoft.AppCenter.Test.Ingestion.Models
|
|||
[TestMethod]
|
||||
public void TestValidateThrowsExceptionWhenAppBuildnIsNull()
|
||||
{
|
||||
const string nullAppBuild = null;
|
||||
var device = new Device(SdkName, SdkVersion, Model, OemName, OsName, OsVersion, Locale, TimeZoneOffset, ScreenSize, AppVersion, nullAppBuild);
|
||||
var device = new Device
|
||||
{
|
||||
SdkName = SdkName,
|
||||
SdkVersion = SdkVersion,
|
||||
OsName = OsName,
|
||||
OsVersion = OsVersion,
|
||||
Locale = Locale,
|
||||
TimeZoneOffset = TimeZoneOffset,
|
||||
AppVersion = AppVersion,
|
||||
AppBuild = null,
|
||||
Model = Model,
|
||||
ScreenSize = ScreenSize,
|
||||
OemName = OemName
|
||||
};
|
||||
Assert.ThrowsException<ValidationException>(() => device.Validate());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,6 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
{
|
||||
public TestLogWithProperties() { }
|
||||
public TestLogWithProperties(DateTime? timestamp, Device device, Guid? sid = default(Guid?), IDictionary<string, string> properties = default(IDictionary<string, string>))
|
||||
: base(timestamp, device, sid, properties) { }
|
||||
: base(device, timestamp, sid, properties) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
public void CheckInitialValuesWithServices()
|
||||
{
|
||||
var servicesNames = new List<string> { "Service0", "Service1", "Service2" };
|
||||
var log = new StartServiceLog(null, null, servicesNames);
|
||||
|
||||
var log = new StartServiceLog();
|
||||
log.Services = servicesNames;
|
||||
Assert.IsNotNull(log.Services);
|
||||
foreach (var serviceName in log.Services)
|
||||
{
|
||||
|
@ -73,21 +73,5 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
Assert.IsTrue(retrievedLog.Services.Contains(serviceName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate that log is not valid with nullable 'Services'
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void ValidateStartServiceLog()
|
||||
{
|
||||
var log = new StartServiceLog
|
||||
{
|
||||
Services = null,
|
||||
Device = new DeviceInformationHelper().GetDeviceInformationAsync().RunNotAsync(),
|
||||
Timestamp = DateTime.Now
|
||||
};
|
||||
|
||||
Assert.ThrowsException<ValidationException>((Action)log.Validate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
|
|||
{
|
||||
public TestLog() {}
|
||||
public TestLog(DateTime? timestamp, Device device, System.Guid? sid = default(System.Guid?))
|
||||
: base(timestamp, device, sid){ }
|
||||
: base(device, timestamp, sid) { }
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче