public void ConvertsDateFilterParametersToUTC() { // Arrange var productionDateStart = DateTime.Now.AddDays(-5); var productionDateEnd = DateTime.Now; var expectedStart = productionDateStart.ToUniversalTime(); var expectedEnd = productionDateEnd.ToUniversalTime(); if (productionDateStart == expectedStart || productionDateEnd == expectedEnd) { Assert.Inconclusive("Production dates are already in UTC"); } FilterLotParameters actualParameters = null; MockLotService .Setup(m => m.GetLotSummaries(It.IsAny <FilterLotParameters>())) .Callback((FilterLotParameters param) => actualParameters = param) .Returns(new SuccessResult <ILotQualitySummariesReturn>(Fixture.Create <ILotQualitySummariesReturn>())); // Act LotsControler.Get(productionStart: productionDateStart, productionEnd: productionDateEnd); // Assert Assert.IsNotNull(actualParameters); Assert.AreEqual(expectedStart, actualParameters.ProductionStartRangeStart); Assert.AreEqual(expectedEnd, actualParameters.ProductionStartRangeEnd); }
public void CallsServiceMethodAsExpected() { // Arrange // Act LotsControler.Put(LotKey, _values); // Assert MockLotService.Verify(m => m.SetLotAttributes(It.IsAny <ISetLotAttributeParameters>()), Times.Once()); }
public async Task Returns200OnSuccess() { // Arrange // Act var result = await LotsControler.Put(LotKey, _values); // Assert Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public void UtilizesUserIdentityProvider() { // Arrange // Act LotsControler.Put(LotKey, _values); // Assert MockUserIdentityProvider.Verify(m => m.SetUserIdentity(It.IsAny <ISetLotAttributeParameters>()), Times.Once()); }
public void CallsServiceMethod() { // Arrange // Act LotsControler.Get(Key); // Assert MockLotService.Verify(m => m.GetLotSummary(Key), Times.Once()); }
public void ReturnsProjectedResult() { // Arrange // Act var result = LotsControler.Get(Key); // Assert Assert.IsNotNull(result); Assert.AreEqual(_expectedReturn, result); }
public async Task Returns400IfValuesAreInvalid() { // Arrange LotsControler.ModelState.AddModelError("", "This is invalid."); // Act var result = await LotsControler.Put(LotKey, _values); // Assert Assert.IsNotNull(result); Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); Assert.IsNotNullOrEmpty(result.ReasonPhrase); }
public async Task Returns500OnFailure() { // Arrange const string message = "an error occurred"; MockLotService.Setup(m => m.SetLotAttributes(It.IsAny <ISetLotAttributeParameters>())) .Returns(new FailureResult <ILotStatInfoReturn>(null, message)); // Act var result = await LotsControler.Put(LotKey, _values); // Assert Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode); Assert.AreEqual(message, result.ReasonPhrase); }
public async Task Returns400OnInvalid() { // Arrange const string message = "invalid stuff happened"; MockLotService.Setup(m => m.SetLotAttributes(It.IsAny <ISetLotAttributeParameters>())) .Returns(new InvalidResult <ILotStatInfoReturn>(null, message)); // Act var result = await LotsControler.Put(LotKey, _values); // Assert Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode); Assert.AreEqual(message, result.ReasonPhrase); }
public void ParametersAreCorrectlyTranslatedToDto() { // Arrange ISetLotAttributeParameters actualParameters = null; MockLotService.Setup(m => m.SetLotAttributes(It.IsAny <ISetLotAttributeParameters>())) .Callback((ISetLotAttributeParameters p) => actualParameters = p) .Returns(new SuccessResult <ILotStatInfoReturn>()); // Act LotsControler.Put(LotKey, _values); // Assert Assert.IsNotNull(actualParameters); Assert.AreEqual(LotKey, actualParameters.LotKey); Assert.AreEqual(((ISetLotAttributeParameters)_values).Attributes, actualParameters.Attributes); }
public void Returns200OnSuccess() { // arrange MockLotService.Setup(m => m.SetLotQualityStatus(It.IsAny <ISetLotStatusParameters>())) .Returns(new SuccessResult <ILotStatInfoReturn>()); const string lotKey = "12345"; const LotQualityStatus expectedStatus = LotQualityStatus.Released; var dto = new SetLotStatusDto { Status = expectedStatus }; // act var response = LotsControler.SetStatus(lotKey, dto); // assert Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void ReturnsServiceResultOnSuccess() { // Arrange const int recordCount = 10; var expectedReturn = Fixture.Build <TestableLotSummariesReturn>() .With(m => m.LotSummaries, Fixture.CreateMany <ILotQualitySummaryReturn>(recordCount).AsQueryable()) .Create(); MockLotService.Setup(m => m.GetLotSummaries(It.IsAny <FilterLotParameters>())) .Returns(() => new SuccessResult <ILotQualitySummariesReturn>(expectedReturn)); Assess.IsNotNull(expectedReturn); Assess.IsNotNull(expectedReturn.LotSummaries); // Act var result = LotsControler.Get(LotTypeEnum.Additive, pageSize: 10); // Assert MockLotService.Verify(m => m.GetLotSummaries(It.IsAny <FilterLotParameters>()), Times.Once()); Assert.AreEqual(recordCount, result.LotSummaries.Count()); }
public void CreatesFilterLotParameterObjectCorrectly() { // Arrange const LotTypeEnum expectedLotType = LotTypeEnum.GRP; const LotProductionStatus expectedStatus = LotProductionStatus.Produced; FilterLotParameters actualParameters = null; MockLotService .Setup(m => m.GetLotSummaries(It.IsAny <FilterLotParameters>())) .Callback((FilterLotParameters param) => actualParameters = param) .Returns(new SuccessResult <ILotQualitySummariesReturn>(Fixture.Create <ILotQualitySummariesReturn>())); // Act LotsControler.Get(expectedLotType, expectedStatus); // Assert Assert.IsNotNull(actualParameters); Assert.AreEqual(expectedLotType, actualParameters.LotType); Assert.AreEqual(expectedStatus, actualParameters.ProductionStatus); }
public void ParametersAreCorrectlyTransposedToDto() { // arrange ISetLotStatusParameters actualParameters = null; MockLotService.Setup(m => m.SetLotQualityStatus(It.IsAny <ISetLotStatusParameters>())) .Callback((ISetLotStatusParameters p) => actualParameters = p) .Returns(new SuccessResult <ILotStatInfoReturn>()); const string lotKey = "12345"; const LotQualityStatus expectedStatus = LotQualityStatus.Released; var dto = new SetLotStatusDto { Status = expectedStatus }; // act LotsControler.SetStatus(lotKey, dto); // assert Assert.IsNotNull(actualParameters); Assert.AreEqual(lotKey, actualParameters.LotKey); Assert.AreEqual(expectedStatus, actualParameters.QualityStatus); }
public void UtilizesUserIdentityProvider() { // arrange const string lotKey = "12345"; const LotQualityStatus expectedStatus = LotQualityStatus.Released; var dto = new SetLotStatusDto { Status = expectedStatus }; SetLotStatusParameter actualParameters = null; MockUserIdentityProvider.Setup(m => m.SetUserIdentity(It.IsAny <SetLotStatusParameter>())) .Callback((SetLotStatusParameter p) => actualParameters = p) .Returns(actualParameters); MockLotService.Setup(m => m.SetLotQualityStatus(It.IsAny <ISetLotStatusParameters>())) .Returns(new SuccessResult <ILotStatInfoReturn>()); // act LotsControler.SetStatus(lotKey, dto); // assert Assert.IsNotNull(actualParameters); MockUserIdentityProvider.Verify(m => m.SetUserIdentity(actualParameters), Times.Once()); }
public void AcceptsPutVerb() { Assert.IsNotNull(LotsControler.GetType().GetMethod("SetStatus") .GetCustomAttribute <HttpPutAttribute>()); }
public void EnforcesClaimsAuthorization() { LotsControler.GetType().AssertClaimsForMethod("SetStatus", new[] { ClaimTypes.QualityControlClaimTypes.LotStatus }, ClaimActions.Full); }
public void EnforcesAntiForgeryTokenValidation() { LotsControler.GetType().AssertAntiForgeryTokenValidationForMethod("SetStatus"); }