From da90e2cb1018fca7777b8b27f7ef610b0ba4aa4f Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Fri, 17 Jul 2015 05:07:05 +0200 Subject: [PATCH] * Yavsc.sln: * Web.csproj: * TestAPI.csproj: * YavscModel.csproj: * Automate.cs: * TaskOutput.cs: * AssemblyInfo.cs: * Service.cs: * FinalStateException.cs: * FrontOfficeController.cs: * InvalidLetterException.cs: * PriceOnItemCount.cs: * TestAutomate.cs: Tests an Automate * packages.config: using Machine.Specifications --- ChangeLog | 4 + TestAPI/ChangeLog | 9 ++ TestAPI/Properties/AssemblyInfo.cs | 47 +++++++ TestAPI/TestAPI.csproj | 73 +++++++++++ TestAPI/TestAutomate.cs | 67 ++++++++++ TestAPI/packages.config | 8 ++ Yavsc.sln | 6 + web/ApiControllers/FrontOfficeController.cs | 21 +++ web/ChangeLog | 5 + web/Web.csproj | 1 - yavscModel/ChangeLog | 10 ++ .../{SetPrice.cs => PriceOnItemCount.cs} | 2 +- yavscModel/FrontOffice/Catalog/Service.cs | 2 +- yavscModel/WorkFlow/Automate.cs | 121 +++++++----------- yavscModel/WorkFlow/FinalStateException.cs | 32 +++++ yavscModel/WorkFlow/InvalidLetterException.cs | 42 ++++++ .../WorkFlow}/TaskOutput.cs | 1 + yavscModel/YavscModel.csproj | 5 +- 18 files changed, 377 insertions(+), 79 deletions(-) create mode 100644 TestAPI/ChangeLog create mode 100644 TestAPI/Properties/AssemblyInfo.cs create mode 100644 TestAPI/TestAPI.csproj create mode 100644 TestAPI/TestAutomate.cs create mode 100644 TestAPI/packages.config rename yavscModel/FrontOffice/Catalog/Billing/{SetPrice.cs => PriceOnItemCount.cs} (96%) create mode 100644 yavscModel/WorkFlow/FinalStateException.cs create mode 100644 yavscModel/WorkFlow/InvalidLetterException.cs rename {web/Admin => yavscModel/WorkFlow}/TaskOutput.cs (99%) diff --git a/ChangeLog b/ChangeLog index 1eff34ab..1fd8b17a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-07-17 Paul Schneider + + * Yavsc.sln: + 2015-06-09 Paul Schneider * Yavsc.sln: creates a packaging project diff --git a/TestAPI/ChangeLog b/TestAPI/ChangeLog new file mode 100644 index 00000000..dedc93bf --- /dev/null +++ b/TestAPI/ChangeLog @@ -0,0 +1,9 @@ +2015-07-17 Paul Schneider + + * TestAPI.csproj: + * AssemblyInfo.cs: + + * TestAutomate.cs: Tests an Automate + + * packages.config: using Machine.Specifications + diff --git a/TestAPI/Properties/AssemblyInfo.cs b/TestAPI/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c0e34c0f --- /dev/null +++ b/TestAPI/Properties/AssemblyInfo.cs @@ -0,0 +1,47 @@ +// +// AssemblyInfo.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 GNU GPL +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("TestAPI")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("GNU GPL")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/TestAPI/TestAPI.csproj b/TestAPI/TestAPI.csproj new file mode 100644 index 00000000..9c36f8ea --- /dev/null +++ b/TestAPI/TestAPI.csproj @@ -0,0 +1,73 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {42B77C89-BF6D-4DB1-8763-6197F4030A95} + Library + TestAPI + TestAPI + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + ..\packages\Machine.Specifications.0.9.3\lib\net45\Machine.Specifications.dll + + + ..\packages\Machine.Specifications.0.9.3\lib\net45\Machine.Specifications.Clr4.dll + + + ..\packages\Machine.Specifications.Runner.Utility.0.9.0\lib\net45\Machine.Specifications.Runner.Utility.dll + + + ..\packages\Spark.1.7.5.3\lib\NET45\Spark.dll + + + ..\packages\Machine.Specifications.Reporting.0.9.0\lib\net45\Machine.Specifications.Reporting.dll + + + ..\packages\Machine.Specifications.Reporting.0.9.0\lib\net45\Machine.Specifications.Reporting.Templates.dll + + + ..\packages\Machine.Specifications.Should.0.7.2\lib\net45\Machine.Specifications.Should.dll + + + nunit + + + + + + + + + + {68F5B80A-616E-4C3C-91A0-828AA40000BD} + YavscModel + + + + + + \ No newline at end of file diff --git a/TestAPI/TestAutomate.cs b/TestAPI/TestAutomate.cs new file mode 100644 index 00000000..ea9a9efb --- /dev/null +++ b/TestAPI/TestAutomate.cs @@ -0,0 +1,67 @@ +// +// MyClass.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 GNU GPL +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +using System; +using Machine.Specifications; +using Yavsc.Model.WorkFlow; +using NUnit.Framework; + +namespace TestAPI +{ + [Subject(typeof(Automate),"simple automate")] + public class CreatingAnAutomate + { + static Automate Subject; + /// + /// The context. + /// + Establish context = () => + { + // ... any mocking, stubbing, or other setup ... + Subject = new Automate(); + }; + + Because of = () => Subject.AddTransition(0,1,'a'); + /// + /// The should be in state 0. + /// + It should_be_in_state_0 = () => Subject.State.ShouldEqual(0); + /// + /// The should not be in state 1. + /// + It should_not_be_in_state_1 = () => Subject.State.ShouldNotEqual(1); + /// + /// The state of the should not indicate o as final. + /// + It should_not_indicate_O_as_final_state = () => Subject.IsInFinalState().ShouldNotEqual(true); + + [Test] + public void DoTheTest() + { + context.Invoke (); + of.Invoke (); + should_be_in_state_0.Invoke (); + should_not_be_in_state_1.Invoke (); + should_not_indicate_O_as_final_state.Invoke (); + } + + } +} + diff --git a/TestAPI/packages.config b/TestAPI/packages.config new file mode 100644 index 00000000..035495c3 --- /dev/null +++ b/TestAPI/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Yavsc.sln b/Yavsc.sln index 1d399537..697049b8 100644 --- a/Yavsc.sln +++ b/Yavsc.sln @@ -33,12 +33,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "pkg", "pkg\pkg.mdproj", "{C6DBD1DC-B619-4DC7-BC92-15693508541E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAPI", "TestAPI\TestAPI.csproj", "{42B77C89-BF6D-4DB1-8763-6197F4030A95}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {42B77C89-BF6D-4DB1-8763-6197F4030A95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {42B77C89-BF6D-4DB1-8763-6197F4030A95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {42B77C89-BF6D-4DB1-8763-6197F4030A95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {42B77C89-BF6D-4DB1-8763-6197F4030A95}.Release|Any CPU.Build.0 = Release|Any CPU {59E1DF7B-FFA0-4DEB-B5F3-76EBD98D5356}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {59E1DF7B-FFA0-4DEB-B5F3-76EBD98D5356}.Debug|Any CPU.Build.0 = Debug|Any CPU {59E1DF7B-FFA0-4DEB-B5F3-76EBD98D5356}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/web/ApiControllers/FrontOfficeController.cs b/web/ApiControllers/FrontOfficeController.cs index 8b17a09b..fecbdb84 100644 --- a/web/ApiControllers/FrontOfficeController.cs +++ b/web/ApiControllers/FrontOfficeController.cs @@ -58,6 +58,19 @@ namespace Yavsc.ApiControllers return CatalogManager.GetCatalog ().GetBrand (brandName).GetProductCategory (prodCategorie); } + /// + /// Authorization denied. + /// + public class AuthorizationDenied : HttpRequestException { + /// + /// Initializes a new instance of the class. + /// + /// Message. + public AuthorizationDenied(string msg) : base(msg) + { + } + } + /// /// Gets the estimate. /// @@ -68,6 +81,14 @@ namespace Yavsc.ApiControllers public Estimate GetEstimate (long id) { Estimate est = wfmgr.ContentProvider.GetEstimate (id); + string username = Membership.GetUser ().UserName; + if (est.Client != username) + if (!Roles.IsUserInRole("Admin")) + if (!Roles.IsUserInRole("FrontOffice")) + throw new AuthorizationDenied ( + string.Format ( + "Auth denied to eid {1} for:{2}", + id, username)); return est; } diff --git a/web/ChangeLog b/web/ChangeLog index 2b2d9cc3..0cc6bd70 100644 --- a/web/ChangeLog +++ b/web/ChangeLog @@ -1,3 +1,8 @@ +2015-07-17 Paul Schneider + + * Web.csproj: + * FrontOfficeController.cs: + 2015-07-15 Paul Schneider * cldr.js: diff --git a/web/Web.csproj b/web/Web.csproj index 65e920e2..e1365b6e 100644 --- a/web/Web.csproj +++ b/web/Web.csproj @@ -155,7 +155,6 @@ - diff --git a/yavscModel/ChangeLog b/yavscModel/ChangeLog index a3516a0e..30d596af 100644 --- a/yavscModel/ChangeLog +++ b/yavscModel/ChangeLog @@ -1,3 +1,13 @@ +2015-07-17 Paul Schneider + + * YavscModel.csproj: + * Automate.cs: + * TaskOutput.cs: + * Service.cs: + * FinalStateException.cs: + * InvalidLetterException.cs: + * PriceOnItemCount.cs: + 2015-07-15 Paul Schneider * ListItem.cs: diff --git a/yavscModel/FrontOffice/Catalog/Billing/SetPrice.cs b/yavscModel/FrontOffice/Catalog/Billing/PriceOnItemCount.cs similarity index 96% rename from yavscModel/FrontOffice/Catalog/Billing/SetPrice.cs rename to yavscModel/FrontOffice/Catalog/Billing/PriceOnItemCount.cs index 0c1c7620..5a73554a 100644 --- a/yavscModel/FrontOffice/Catalog/Billing/SetPrice.cs +++ b/yavscModel/FrontOffice/Catalog/Billing/PriceOnItemCount.cs @@ -26,7 +26,7 @@ namespace Yavsc.Model.FrontOffice.Billing /// /// A set price. /// - public class SetPrice: Price + public class PriceOnItemCount: Price { /// /// Gets or sets the minimum count for this setprice. diff --git a/yavscModel/FrontOffice/Catalog/Service.cs b/yavscModel/FrontOffice/Catalog/Service.cs index 103d62aa..e1cfd7a3 100644 --- a/yavscModel/FrontOffice/Catalog/Service.cs +++ b/yavscModel/FrontOffice/Catalog/Service.cs @@ -24,7 +24,7 @@ namespace Yavsc.Model.FrontOffice /// Gets or sets the set prices. /// /// The set prices. - public SetPrice[] SetPrices { get; set; } + public PriceOnItemCount[] SetPrices { get; set; } /// /// Role names involved in this kind of service diff --git a/yavscModel/WorkFlow/Automate.cs b/yavscModel/WorkFlow/Automate.cs index f2b06140..703b8f20 100644 --- a/yavscModel/WorkFlow/Automate.cs +++ b/yavscModel/WorkFlow/Automate.cs @@ -26,103 +26,75 @@ namespace Yavsc.Model.WorkFlow /// /// Automate. /// - public class Automate + public class Automate { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the Automate class. /// public Automate () { - } - - private List> eventids = - new List>(); - private List> stateids = - new List>(); - private IEquatable startingstateid ; - private List> endingstateids = - new List>(); - private Dictionary,Dictionary,IEquatable>> transitions = - new Dictionary, Dictionary, IEquatable>>(); - + private Dictionary> transitions = + new Dictionary>(); + private List letters = new List(); + private List states = new List(); /// - /// Sets the state of the starting. + /// Gets or sets the state. /// - /// Starting state identifier. - public void SetStartingState(IEquatable startingStateId) - { - if (endingstateids.Contains (startingStateId)) - throw new InvalidOperationException ("endingstateids.Contains (startingStateId)"); - if (!stateids.Contains (startingStateId)) - stateids.Add (startingStateId); - startingstateid = startingStateId; - } + /// The state. + public TState State { get; set; } /// - /// Sets the state of the ending. + /// Gets or sets the starting state. /// - /// Ending state identifier. - public void SetEndingState(IEquatable endingStateId) - { - - if (startingstateid==endingStateId) - throw new InvalidOperationException ("startingstateid==endingStateId"); - if (!stateids.Contains (endingStateId)) - stateids.Add (endingStateId); - if (!endingstateids.Contains (endingStateId)) - endingstateids.Add (endingStateId); - } - + /// The state. + public TState StartingState { get; set; } /// /// Adds the transition. /// - /// Starting state identifier. - /// Ending state identifier. - /// Event identifier. - public void AddTransition( - IEquatable startingStateId, - IEquatable endingStateId, - IEquatable eventId) + /// Start. + /// End. + /// Letter. + public virtual void AddTransition( + TState start, + TState end, + TLetter letter) { - if (!stateids.Contains (startingStateId)) - stateids.Add (startingStateId); - if (!stateids.Contains (endingStateId)) - stateids.Add (endingStateId); - - Dictionary,IEquatable> currentNode = transitions [startingStateId]; - if (currentNode == null) { + if (!states.Contains (start)) + states.Add (start); + if (!states.Contains (end)) + states.Add (end); + if (!letters.Contains (letter)) + letters.Add (letter); + Dictionary node = null; + if (!transitions.ContainsKey(start)) transitions.Add( - startingStateId, - currentNode = - new Dictionary, IEquatable> ()); - } - currentNode [eventId] = endingStateId; - if (!eventids.Contains (eventId)) - eventids.Add (eventId); + start, + node = + new Dictionary ()); + else node = transitions [start]; + if (node.ContainsKey (letter)) + throw new NotImplementedException ("Automates indéterministes"); + node.Add(letter, end); } - /// - /// Gets or sets the state. - /// - /// The state. - public IEquatable State { get; set; } /// /// Move this instance according the specified eventId. /// /// Event identifier. - public void Move(IEquatable eventId) + public void Aggregate(TLetter eventId) { if (State == null) throw new InvalidOperationException ("Set the current state or reset the automate before"); - Dictionary,IEquatable> node = transitions [State]; - if (node == null) // no transition found - return; - IEquatable nextState = node [eventId]; + Dictionary node = transitions [State]; + if (node == null) // no transition found from this state + // it is final. + throw new FinalStateException(); + TState nextState = node [eventId]; if (nextState == null) // no transition found for this event - return; + throw new InvalidLetterException(eventId); State = nextState; } @@ -131,7 +103,7 @@ namespace Yavsc.Model.WorkFlow /// public void Reset() { - State = startingstateid; + State = StartingState; } /// @@ -139,10 +111,9 @@ namespace Yavsc.Model.WorkFlow /// reset all of its properties /// public void FactoryReset() { - State = null; - startingstateid = null; - endingstateids.Clear (); - eventids.Clear (); + State = default(TState); + StartingState = default(TState); + letters.Clear (); transitions.Clear (); } @@ -152,7 +123,7 @@ namespace Yavsc.Model.WorkFlow /// true if this instance is in final state; otherwise, false. public bool IsInFinalState() { - return endingstateids.Contains (State); + return !transitions.ContainsKey(this.State); } } diff --git a/yavscModel/WorkFlow/FinalStateException.cs b/yavscModel/WorkFlow/FinalStateException.cs new file mode 100644 index 00000000..a7f2c0df --- /dev/null +++ b/yavscModel/WorkFlow/FinalStateException.cs @@ -0,0 +1,32 @@ +// +// Automate.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 Paul Schneider +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; + +namespace Yavsc.Model.WorkFlow +{ + public class FinalStateException : Exception + { + } + + +} + diff --git a/yavscModel/WorkFlow/InvalidLetterException.cs b/yavscModel/WorkFlow/InvalidLetterException.cs new file mode 100644 index 00000000..02c068c2 --- /dev/null +++ b/yavscModel/WorkFlow/InvalidLetterException.cs @@ -0,0 +1,42 @@ +// +// Automate.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 Paul Schneider +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see . +using System; +using System.Collections.Generic; + +namespace Yavsc.Model.WorkFlow +{ + /// + /// Invalid letter exception. + /// + public class InvalidLetterException : Exception + { + /// + /// Initializes a new instance of the class. + /// + /// Letter. + public InvalidLetterException(object letter):base(letter.ToString()) + { + } + } + + +} + diff --git a/web/Admin/TaskOutput.cs b/yavscModel/WorkFlow/TaskOutput.cs similarity index 99% rename from web/Admin/TaskOutput.cs rename to yavscModel/WorkFlow/TaskOutput.cs index 078099bd..50318b55 100644 --- a/web/Admin/TaskOutput.cs +++ b/yavscModel/WorkFlow/TaskOutput.cs @@ -3,6 +3,7 @@ using System.ComponentModel; namespace Yavsc.Admin { + /// /// Task output. /// diff --git a/yavscModel/YavscModel.csproj b/yavscModel/YavscModel.csproj index 924a652e..d255db65 100644 --- a/yavscModel/YavscModel.csproj +++ b/yavscModel/YavscModel.csproj @@ -119,7 +119,6 @@ - @@ -160,6 +159,10 @@ + + + +