예제 #1
0
            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);
            }
예제 #2
0
            public void CallsServiceMethodAsExpected()
            {
                // Arrange
                // Act
                LotsControler.Put(LotKey, _values);

                // Assert
                MockLotService.Verify(m => m.SetLotAttributes(It.IsAny <ISetLotAttributeParameters>()), Times.Once());
            }
예제 #3
0
            public async Task Returns200OnSuccess()
            {
                // Arrange
                // Act
                var result = await LotsControler.Put(LotKey, _values);

                // Assert
                Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            }
예제 #4
0
            public void UtilizesUserIdentityProvider()
            {
                // Arrange
                // Act
                LotsControler.Put(LotKey, _values);

                // Assert
                MockUserIdentityProvider.Verify(m => m.SetUserIdentity(It.IsAny <ISetLotAttributeParameters>()), Times.Once());
            }
예제 #5
0
            public void CallsServiceMethod()
            {
                // Arrange
                // Act
                LotsControler.Get(Key);

                // Assert
                MockLotService.Verify(m => m.GetLotSummary(Key), Times.Once());
            }
예제 #6
0
            public void ReturnsProjectedResult()
            {
                // Arrange
                // Act
                var result = LotsControler.Get(Key);

                // Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(_expectedReturn, result);
            }
예제 #7
0
            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);
            }
예제 #8
0
            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);
            }
예제 #9
0
            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);
            }
예제 #10
0
            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);
            }
예제 #11
0
            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);
            }
예제 #12
0
            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());
            }
예제 #13
0
            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);
            }
예제 #14
0
            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);
            }
예제 #15
0
            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());
            }
예제 #16
0
 public void AcceptsPutVerb()
 {
     Assert.IsNotNull(LotsControler.GetType().GetMethod("SetStatus")
                      .GetCustomAttribute <HttpPutAttribute>());
 }
예제 #17
0
 public void EnforcesClaimsAuthorization()
 {
     LotsControler.GetType().AssertClaimsForMethod("SetStatus", new[] { ClaimTypes.QualityControlClaimTypes.LotStatus }, ClaimActions.Full);
 }
예제 #18
0
 public void EnforcesAntiForgeryTokenValidation()
 {
     LotsControler.GetType().AssertAntiForgeryTokenValidationForMethod("SetStatus");
 }